CSUACM :1067 1 VS 1

1067: 1 VS 1

Submit Page      Summary      Time Limit: 1 Sec       Memory Limit: 128 Mb       Submitted: 438       Solved: 294    

Description

      Alice and Bob are playing the game SanguoSha 1VS1.If Alice take a card or use a card (it may be slash,missed,peach,duel,sabotage or theft and so on) or discard (sometimes he does not need to throw any card) we will write down an uppercase 'A', if Bob does this, of course, we will write down the letter 'B'. Tell me the length of the longest operation combo performed by either player.

Input


      There are several test cases, each test case contains only a string composed of uppercaser 'A' and 'B'.The input will finish with the end of file.The length of the string is no more than 1000.

Output


     For each the case, output an integer indicate for the length.

Sample Input

AAABBAAAAA
AABBBBAA
AAAAAAAA

Sample Output

5
4
8
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
bool jixu(int a,int b)
{
	return a>b;   //降序 
}
int main()
{
	int a[1005],max,b;
	char s[1005];
	while(std::cin>>s)
	{
		for(int i=0;i<1005;i++)
		       a[i]=1;         //给数组赋初值 
		b=strlen(s);
		for(int i=0,j=0;i<b;i++)
		{
			if(s[i]==s[i+1])
			{
				a[j]=a[j]+1;
			}
			else
			    j++;
		}
		sort(a,a+1005,jixu);
		max=a[0];	
		cout<<max<<endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40514660/article/details/79996341
今日推荐