字符串 A. Angry Students

**

字符串 A. Angry Students

**

A. Angry Studentstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt’s a walking tour day in SIS.Winter, so tt 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 ii in the string describing a group then they will throw a snowball at the student that corresponds to the character with index i+1i+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.InputThe first line contains a single integer tt — the number of groups of students (1≤t≤1001≤t≤100). The following 2t2t lines contain descriptions of groups of students.The description of the group starts with an integer kiki (1≤ki≤1001≤ki≤100) — the number of students in the group, followed by a string sisi, consisting of kiki letters “A” and “P”, which describes the ii-th group of students.OutputFor every group output single integer — the last moment a student becomes angry.

题意:找出A后面跟的P的最大个数

#include<stdio.h>
int main()
{
 int n,num,status=0,cont=0,max;
 char c;
 scanf("%d",&n);
 while(n--) 
 {
  status=0;
  max=0;cont=0;
  scanf("%d\n",&num);
  while((c=getchar())!='\n')
  {
   if(c=='A')
   {
    status=1;
    if(cont>max) max=cont;
    cont=0;
   }
   else
   {
    if(status) cont++;
   }
  }
  if(cont>max) max=cont;
  printf("%d\n",max);
 }
 return 0;
 } 
发布了1 篇原创文章 · 获赞 0 · 访问量 12
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 1024 设计师: 上身试试

分享到微信朋友圈

×

扫一扫,手机浏览