当前位置:网站首页>771. The longest consecutive character in a string
771. The longest consecutive character in a string
2022-07-28 22:38:00 【Hunter_ Kevin】
subject
Find the longest consecutive character in a string , Output the character and its occurrence times , There are no white space characters in the string ( Space 、 Return and tab), If there is more than one such character , Then the first one is output .
Input format
Enter the integer in the first line N, Number of groups representing test data .
Each group of data occupies one row , Contains a string that does not contain white space characters , The string length does not exceed 200.
Output format
All in one line , Output the longest consecutive characters and their occurrences , Space separates the middle .
sample input :
2
aaaaabbbbbcccccccdddddddddd
abcdefghigk
sample output :
d 10
a 1
Code
#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;
}
边栏推荐
- 使用webWorker执行后台任务
- Mysql8.0 cannot authorize users or prompt you are not allowed to create a user with grant
- 75. Color classification (medium array double pointer sorting)
- Baidu map usage
- Win11 how to open software notification
- 775. 倒排单词
- Sword finger offer II 067. maximum XOR (medium prefix tree bit operation array)
- mysql8.0无法给用户授权或提示You are not allowed to create a user with GRANT的问题
- Sword finger offer II 053. Medium order successor in binary search tree (medium binary search tree DFS)
- Paddlenlp is based on ernir3.0 text classification. Take the crime prediction task of cail2018-small dataset as an example [multiple tags]
猜你喜欢

静态成员static详解

PaddleNLP基于ERNIR3.0文本分类以CAIL2018-SMALL数据集罪名预测任务为例【多标签】
![[Ruiji takeout project]day4 - dish management](/img/2a/2d9deb7a583aa37b38a67ef2c74ee7.png)
[Ruiji takeout project]day4 - dish management

98. Verify binary search tree (medium binary search tree DFS)

SQL injection less38 (Stack Injection)

XXX port is already in use

105. Construct binary tree from preorder and inorder traversal sequence (medium binary tree DFS hash table binary tree)

Research cup element recognition multi label classification task based on ernie-3.0 cail2019 method

imx6q gpio复用
![[virtual machine _2]-hyper-v and vmware/virtualbox cannot coexist](/img/90/c481a817dc91d7e5247dd8e3ee1dae.png)
[virtual machine _2]-hyper-v and vmware/virtualbox cannot coexist
随机推荐
Use webworker to perform background tasks
软考网络工程师
Mysql内置函数
Sword finger offer II 058. schedule (medium design segment tree treemap ordered set)
Log4j vulnerability elk platform processing method (logstah5.5.1)
79. Word search (medium string array matrix backtracking)
Sword finger offer II 055. Binary search tree iterator (medium binary search tree iterator)
ES6, deep copy, shallow copy
Ngrok intranet penetration
ngx+sql环境离线安装日志(rpm安装)
(翻译)图技术简明历史
MySQL built-in functions
What does GPRS network mean
Sword finger offer II 054. Sum of all values greater than or equal to nodes (medium binary search tree DFS)
What is time complexity
容器化配置启动redis集群 单机6节点 3主3从
Integrating database Ecology: using eventbridge to build CDC applications
gprs网络指的是什么
纪念一下第一次写的线段树了喽(对应洛谷3372)
imx6q gpio复用