AcWing 771. 字符串中最长的连续出现的字符
【摘要】
文章目录
AcWing 771. 字符串中最长的连续出现的字符AC代码
AcWing 771. 字符串中最长的连续出现的字符
本题链接:AcWing 771. 字符串中最长的连续出现的...
AcWing 771. 字符串中最长的连续出现的字符
本题链接:AcWing 771. 字符串中最长的连续出现的字符
本博客给出本题截图:
AC代码
代码:
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
while (n -- )
{
string str;
cin >> str;
int cnt = 0;
char c;
for (int i = 0; i < str.size(); i ++ )
{
int j = i;
while (j < str.size() && str[j] == str[i]) j ++ ;
if (j - i > cnt) cnt = j - i, c = str[i];
i = j - 1;
}
cout << c << ' ' << cnt << endl;
}
return 0;
}
文章来源: chen-ac.blog.csdn.net,作者:辰chen,版权归原作者所有,如需转载,请联系作者。
原文链接:chen-ac.blog.csdn.net/article/details/120642273
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)