当前位置:网站首页>771. 字符串中最长的连续出现的字符
771. 字符串中最长的连续出现的字符
2022-07-28 20:50:00 【Hunter_Kevin】
题目
求一个字符串中最长的连续出现的字符,输出该字符及其出现次数,字符串中无空白字符(空格、回车和 tab),如果这样的字符不止一个,则输出第一个。
输入格式
第一行输入整数 N,表示测试数据的组数。
每组数据占一行,包含一个不含空白字符的字符串,字符串长度不超过 200。
输出格式
共一行,输出最长的连续出现的字符及其出现次数,中间用空格隔开。
输入样例:
2
aaaaabbbbbcccccccdddddddddd
abcdefghigk
输出样例:
d 10
a 1
代码
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
while (n--)
{
string s;
cin >> s;
char ch;
int cnt = 0;
for(int i = 0; s[i]; i++)
{
int j = i;
while(j < s.size() && s[i] == s[j]) j++;
if(cnt < j-i) cnt = j-i, ch = s[i];
i = j-1;
}
cout << ch << ' ' << cnt << endl;
}
return 0;
}
边栏推荐
- Sword finger offer II 053. Medium order successor in binary search tree (medium binary search tree DFS)
- Sword finger offer II 067. maximum XOR (medium prefix tree bit operation array)
- SQL注入 Less38(堆叠注入)
- 微信小程序剪切图片的功能
- Hcip experiment (12)
- JS implementation generates a random key of specified length
- [binary tree] pseudo palindrome path in binary tree
- The blueprint of flask complements openpyxl
- imx6q gpio复用
- 软考网络工程师
猜你喜欢
随机推荐
HCIP(8)
Att & CK Threat Intelligence
容器化配置启动redis集群 单机6节点 3主3从
HCIP(13)
[Ruiji takeout project] Day5 - Chapter 6 mobile verification code login
Sword finger offer II 058. schedule (medium design segment tree treemap ordered set)
JS array merging, de duplication, dimensionality reduction (es6: extended operator, set)
When can I sign up for the 2022 class I constructor examination?
Ngrok intranet penetration
How to install WiFi correctly
【CVPR 2021】Cylinder3D:用于LiDAR点云分割的圆柱体非对称3D卷积网络
微信小程序里button点击的时候会边框有黑线
Remember the first line segment tree (corresponding to Luogu 3372)
【转载】token令牌在登录场景使用
98. Verify binary search tree (medium binary search tree DFS)
JMeter installs third-party plug-ins plugins Manager
Alibaba cloud CDN practice
Jmeter 安装第三方插件 Plugins Manager
tutorial/detailed_ workflow. Ipynb quantitative finance qlib Library
tutorial/detailed_workflow.ipynb 量化金融Qlib库





![[Ruiji takeout project]day4 - dish management](/img/2a/2d9deb7a583aa37b38a67ef2c74ee7.png)



