AcWing 771. 字符串中最长的连续出现的字符
1. 地址
https://www.acwing.com/problem/content/description/773/
2. 题解
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
int main(){
int n;
int sum;
int max;
int maxi;
string s;
scanf("%d",&n);
while(n--){
cin >> s;
max = 0;
maxi = 0;
for(int i=0;i<s.size();i++){
sum = 0;
int j = i;
while(j < s.size() && s[i] == s[j]){
j++;
sum++;
}
if(sum > max){
max = sum;
maxi = i;
}
i = j-1;
}
printf("%c %d\n",s[maxi],max);
}
return 0;
}
/*
本题采用双指针算法求解(第一类双指针算法)
模版如下:
for(int i=0;i<n;i++){
int j = i;
while(j < n && s[i] == s[j]){
j++;
}
i = j-1;
}
*/
标签:771,int,max,maxi,字符串,include,AcWing
From: https://www.cnblogs.com/gao79135/p/17381601.html