Description:
遇到了ogo可以变成***如果ogo后面有go统统忽略,输出结果
Solution:
哎如果我一开始对题意的解读如上的话,就不会被整的那么麻烦了
Code:
#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn = 150; /***找到一个题目的规律,做题的方法是多么的重要!!***/ /***以后没有好的方法,不打代码***/ char s[maxn]; int main() { int len; while(~scanf("%d%s",&len,s)) { for(int i = 0;i < len;) { if(s[i] == 'o' && s[i + 1] == 'g' && s[i + 2] == 'o') { printf("***"); i += 3; while(s[i] == 'g' && s[i+1] == 'o') { i += 2; } } else { printf("%c",s[i]); i++; } } printf(" "); } return 0; }
看看我的超级麻烦bug多多的模拟!!!
一开始真的读错题了!
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; const int maxn = 1e3; char s[maxn]; char out[maxn]; char cmp[200] = "ogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogo"; int main() { int len; while(~scanf("%d",&len)) { scanf("%s",s); int mpid = 0; int outsid = 0; for(int i = 0;i < len;++i) { out[outsid++] = s[i]; if(s[i] == cmp[mpid]) { //printf(" %d ",mpid); mpid++; } else { //cout<<mpid<<endl; if(mpid == 1) { outsid -= 1; i -= 1; } else if(mpid == 2) { mpid = 0; } else if(mpid % 2 == 1) { outsid -= mpid + 1; out[outsid++] = '*'; out[outsid++] = '*'; out[outsid++] = '*'; i--; } else if(mpid % 2 == 0 && mpid != 0) { outsid -= mpid + 1; out[outsid++] = '*'; out[outsid++] = '*'; out[outsid++] = '*'; out[outsid++] = 'g'; out[outsid++] = s[i]; } mpid = 0; } } if(mpid > 2) { if(mpid % 2 == 1) { outsid -= mpid; out[outsid++] = '*'; out[outsid++] = '*'; out[outsid++] = '*'; } else if(mpid % 2 == 0) { outsid -= mpid; out[outsid++] = '*'; out[outsid++] = '*'; out[outsid++] = '*'; out[outsid++] = 'g'; } } out[outsid] = ' '; printf("%s ",out); } return 0; }