Codeforces Round #612 (Div. 2) A. Angry Students

A. Angry Students(按要求做)

题意 打雪仗 :
简单总结就是找最后一个A 后面有多少个P

代码实现

#include <cstdio>
#include <stdio.h>
#include <iostream>
char s[1005];
int main()
{

    int t;
    scanf("%d", &t);
    while (t--)
    {
        int n;
        scanf("%d %s", &n, s+1);
        bool flag;
        int cnt=-1;
        do
        {
            flag=0; cnt++;
            for (int i=n-1; i>=1; i--)
                if (s[i]=='A'&&s[i+1]=='P')
                { s[i+1]='A';
                     flag=1;
                }
        } while (flag);
        printf("%d\n", cnt);
    }
    return 0;
}

发布了289 篇原创文章 · 获赞 112 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/king9666/article/details/103916619
今日推荐