AcWing 771. 字符串中最长的连续出现的字符
原题链接
中等
作者:
zhiling
,
2019-05-21 17:29:04
,
所有人可见
,
阅读 1048
#include<cstring>
#include <bits/stdc++.h>
#include <algorithm>
typedef long long LL;
const int N = 210;
using namespace std;
int main()
{
int n;
char str[N];
char count1[N];
int count2[N];
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%s",str);
int j=0;
count1[j]=str[0];
count2[j]=1;
for(int k=1; str[k] != '\0'; k++)
{
if(str[k] == count1[j])
{
count2[j]++;
}
else
{
j++;
count1[j] = str[k];
count2[j]=1;
}
}
int maxIndex=0;
for(int k=1;k<=j;k++)
{
if(count2[k]>count2[maxIndex])
{
maxIndex=k;
}
}
printf("%c %d\n",count1[maxIndex],count2[maxIndex]);
}
return 0;
}