Codeforces--447Div.2--A

题目

给出一串字符,题目要求输出有多少个QAQ,不限制中间穿插了多少个字符,不同的QAQ可以使用同一个Q或者A。
由于数据量较少,我是暴力遍历出来的,贼菜
代码如下:

#include<cstdio>
#include<cstring>
char a[105];
int main()
{
    int count=0;
    scanf("%s",a);
    int len=strlen(a);
    for(int i=0;i<len;i++)
    {
        if(a[i]=='Q')
        {
            for(int j=i+1;j<len;j++)
            {
                if(a[j]=='A')
                {
                    for(int k=j;k<len;k++)
                    {
                        if(a[k]=='Q')
                        count++;
                    }
                }
            }
        }
    }
    printf("%d\n",count);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_36428171/article/details/78608238