Interview with Oleg

点击打开链接

题目的意思就是当字符串里有ogo就把它们换成***,而且当ogo后面还有gogogo…………也相当与一个ogo,比赛的时候没想到怎么找到这个长字符串…………,暴力

#include
#include
#include
#include
#include
#include
#include
using namespace std;
int main()
{
    int n;
    char a[101];
    scanf("%d%s",&n,a);
    for(int i=0;i    {
        if(a[i]=='o'&&a[i+1]=='g'&&a[i+2]=='o')
        {
           for(int j=i+3;j<=n;j++)
           {
               if(a[j]=='g'&&a[j+1]=='o')
               {
                   j++;
               }
               else
               {
                   i=j-1;
                   printf("***");
                   break;
               }
           }
        }
        else
        {
            printf("%c",a[i]);
        }
    }
    printf("\n");
}

你可能感兴趣的:(Interview with Oleg)