題意就是給你一個長度爲n的字符串,將字符串按要求轉化。如果字符串出現ogo,就替換成***。並且ogo之後連續的go捨去。
#include <bits/stdc++.h>
using namespace std;
char s[105];
bool judge(int m)
{
if(s[m+1]=='g'&&s[m+2]=='o')
return true;
return false;
}
int main()
{
int n;
while(cin>>n)
{
cin>>s;
for(int i=0;i<n;i++)
{
if(s[i]=='o'&&s[i+1]=='g'&&s[i+2]=='o')
{
i=i+2;
while(judge(i))
{
i+=2;
}
cout<<"***";
}
else
cout<<s[i];
}
cout<<endl;
}
}