ACM:M: 1 VS 1

xiaoxiao2021-02-27  225

ACM:M: 1 VS 1

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 <cstdio>#include <cstring>#include <vector>#include <cmath>#include <algorithm>#include <string>#include <ctime>#define LL long long#define MAX(a,b)((a)>(b)?a:b)#define MIN(a,b)((a)<(b)?a:b)#define INF 0x7ffffff#define N 1005#define M 15using namespace std;//char str[N];int main(){ string str; while(cin>>str) { int max=0; int con=1; for(int i=0;i<str.length();i++) { if(str[i]==str[i+1]) { con++; if(con>max) max=con; } else con=1; } cout<<max<<endl; } return 0;}
转载请注明原文地址: https://www.6miu.com/read-9621.html

最新回复(0)