给定一个长度为 n 的字符串,字符串中的每个字符要么是 P,要么是 A。
其中字符 P 的价值都为 0,字符 A 的价值等于其右侧与其直接相邻的连续 P 的个数。
例如,PAPAAPP 中第 1 个 A 的价值为 1,第 2 个 A 的价值为 0,第 3 个 A 的价值为 2。
请你计算并输出字符串中价值最大的字符的价值。
输入格式
第一行包含整数 T,表示共有 T 组测试数据。
每组数据第一行包含整数 n。
第二行包含一个长度为 n 的字符串,字符串中的每个字符要么是 P,要么是 A。
输出格式
每组数据输出一行结果,一个整数,表示字符串中价值最大的字符的价值。
数据范围
前三个测试点满足1≤T≤10,1≤n≤12。
所有测试点满足 1≤T≤100,1≤n≤100。
输入样例1:
- 2
- 7
- PAPAAPP
- 4
- PPAP
输出样例1:
- 2
- 1
输入样例2:
- 3
- 12
- APPAPPPAPPPP
- 3
- AAP
- 3
- PPA
输出样例2:
- 4
- 1
- 0
- /*
- * @Description: To iterate is human, to recurse divine.
- * @Autor: Recursion
- * @Date: 2022-08-20 23:56:20
- * @LastEditTime: 2022-08-21 00:00:30
- */
- #include
- #define LL long long
- using namespace std;
- const int maxn = 1e6 + 10;
- const int mod = 1e9 + 7;
- const int INF = 1e9 + 10;
- const int N = 1e6;
- string s;
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
-
- int t;
- cin >> t;
- while(t--){
- int n;
- cin >> n;
- cin >> s;
-
- int res = 0;
- for(int i = 0;i < n;i ++){
- if(s[i] == 'A'){
- int j = i + 1;
- while(j < n && s[j] == 'P') j ++;
- res = max(res,j - i - 1);
- i = j - 1;
- }
- }
-
- cout << res << endl;
-
- }
-
-
- return 0;
- }