31: The longest consecutive character in a string, and the longest character in a 31 string
31: The longest consecutive character in a string
- View
- Submit
- Statistics
- Question
-
Total time limit:
-
1000 ms
-
Memory limit:
-
65536kB
-
Description
-
Returns the longest consecutive character in a string and the number of occurrences of the character. The string contains no blank characters (space, carriage return, and tab). If there are more than one such character, the earliest character is output.
-
Input
-
A line. It is a string that does not contain white spaces. the string length is less than 200 characters.
-
Output
-
For a row, the maximum consecutive characters and the maximum number of consecutive occurrences are output. Separate them with a space in the middle.
-
Sample Input
-
aaaaadbbbbbcccccccdddddddddd
-
Sample output
-
d 10
-
Source
-
6373
-
1 #include<iostream> 2 #include<cstdio> 3 #include<queue> 4 #include<cmath> 5 #include<cstring> 6 using namespace std; 7 char a[10001]; 8 int now; 9 int maxn=-1;10 char ans;11 int main() 12 {13 gets(a);14 int l=strlen(a);15 for(int i=0;i<l;i++)16 {17 if(a[i]==a[i+1])18 now++;19 else20 {21 now++;22 if(now>maxn)23 {24 maxn=now;25 ans=a[i];26 }27 now=0; 28 }29 }30 cout<<ans<<" "<<maxn;31 return 0;32 }