codeforces 1287A -Angry Students(模拟)
It’s a walking tour day in SIS.Winter, so t groups of students are visiting Torzhok. Streets of Torzhok are so narrow that students have to go in a row one after another.
Initially, some students are angry. Let’s describe a group of students by a string of capital letters “A” and “P”:
“A” corresponds to an angry student “P” corresponds to a patient student Such string describes the row from the last to the first student.
Every minute every angry student throws a snowball at the next student. Formally, if an angry student corresponds to the character with index i in the string describing a group then they will throw a snowball at the student that corresponds to the character with index i+1 (students are given from the last to the first student). If the target student was not angry yet, they become angry. Even if the first (the rightmost in the string) student is angry, they don’t throw a snowball since there is no one in front of them.
Let’s look at the first example test. The row initially looks like this: PPAP. Then, after a minute the only single angry student will throw a snowball at the student in front of them, and they also become angry: PPAA. After that, no more students will become angry.
Your task is to help SIS.Winter teachers to determine the last moment a student becomes angry for every group.
Input The first line contains a single integer t — the number of groups of students (1≤t≤100). The following 2t lines contain descriptions of groups of students.
The description of the group starts with an integer ki (1≤ki≤100) — the number of students in the group, followed by a string si, consisting of ki letters “A” and “P”, which describes the i-th group of students.
Output For every group output single integer — the last moment a student becomes angry.
Examples Input 1 4 PPAP Output 1 Input 3 12 APPAPPPAPPPP 3 AAP 3 PPA Output 4 1 0 Note In the first test, after 1 minute the state of students becomes PPAA. After that, no new angry students will appear.
In the second tets, state of students in the first group is:
after 1 minute — AAPAAPPAAPPP after 2 minutes — AAAAAAPAAAPP after 3 minutes — AAAAAAAAAAAP after 4 minutes all 12 students are angry In the second group after 1 minute, all students are angry.
#include <bits/stdc++.h>
using namespace std;
template <typename t>
void read(t &x)
{
char ch = getchar();
x = 0;
t f = 1;
while (ch < '0' || ch > '9')
f = (ch == '-' ? -1 : f), ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
x *= f;
}
#define wi(n) printf("%d ", n)
#define wl(n) printf("%lld ", n)
#define rep(m, n, i) for (int i = m; i < n; ++i)
#define rrep(m, n, i) for (int i = m; i > n; --i)
#define P puts(" ")
typedef long long ll;
#define MOD 1000000007
#define mp(a, b) make_pair(a, b)
#define N 10005
#define fil(a, n) rep(0, n, i) read(a[i])
//---------------https://lunatic.blog.csdn.net/-------------------//
string s;
int k,t;
int main()
{
read(t);
while (t--)
{
read(k);
cin >> s;
int count = 0, max = 0, flag = 0;
for (int i = 0; i < k;)
if (s[i] == 'A')
{
count = 0, i++;
while (s[i] == 'P')
count++, i++;
if (count > max)
max = count;
}
else
i++;
wi(max);
P;
}
return 0;
}
- 如何在Redhat7.3的CDH5.14中启用Kerberos
- 如何使用SAML配置Cloudera Manager的身份验证
- 如何使用Shibboleth搭建IDP服务并集成OpenLDAP
- 如何获取Hive正在执行或者已结束的的MapReduce作业的SQL语句
- 如何启用Oozie的HA
- 如何使用Oozie API接口向Kerberos环境的CDH集群提交Spark作业
- 如何降级Cloudera Manager和CDH
- 如何在CDH中安装和使用StreamSets
- 如何使用Oozie API接口向非Kerberos环境的CDH集群提交Shell工作流
- 如何使用Oozie API接口向非Kerberos环境的CDH集群提交Java作业
- 如何通过Livy的RESTful API接口向Kerberos环境的CDH集群提交作业
- 如何使用Oozie API接口向非Kerberos环境的CDH集群提交Spark作业
- Joomla 权限提升漏洞(CVE-2016-9838)分析
- Firefox - SVG cross domain cookie vulnerability
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- PHP 实现超简单的SESSION与COOKIE登录验证功能示例
- PHP 图像处理与SESSION制作超简单验证码的方法示例
- 简述PHP7.4 新特性和废弃的功能
- laravel5.1框架下的批量赋值实现方法分析
- Laravel框架环境与配置操作实例分析
- 记Laravel调用Gin接口调用formData上传文件的实现方法
- Laravel框架视图和模型操作方法分析
- 接口测试框架实战(六) | 配置的数据驱动
- PHP连续签到功能实现方法详解
- PHP实现发送微博消息功能完整示例
- php实现快速对二维数组某一列进行组装的方法小结
- PHP实现提取多维数组指定一列的方法总结
- PHP实现二维数组(或多维数组)转换成一维数组的常见方法总结
- Laravel框架Eloquent ORM简介、模型建立及查询数据操作详解
- Laravel框架下载,安装及路由操作图文详解