A. Angry Students

http://codeforces.com/contest/1287/problem/A

找到出现A之后最大连续的P的数量即可

代码

 1 #include <iostream>
 2 #include <string>
 3 #include <stdio.h>
 4 #include <string.h>
 5 #include <math.h>
 6 #include <algorithm>
 7 
 8 using namespace std;
 9 
10 int main()
11 {
12     int t, n;
13     string s;
14     cin>>t;
15     while(t--)
16     {
17         cin>>n;
18         cin>>s;
19         bool flag = false;
20         int num = 0;
21         int ans = 0;
22         for (int i = 0; i < s.size(); ++i)
23         {
24             if (flag)
25             {
26                 if (s[i] == 'A')
27                 {
28                     num = 0;
29                 }
30                 else
31                 {
32                     num++;
33                     ans = max(ans, num);
34                 }
35             }
36             else
37             {
38                 if(s[i] == 'A')
39                 {
40                     flag = true;
41                 }
42                 else
43                 {
44                     continue;
45                 }
46             }
47         }
48         cout<<ans<<endl;
49     }
50     return 0;
51 }
原文地址:https://www.cnblogs.com/liulangye/p/12161709.html