TJU Counting Letters
来源:互联网 发布:易语言皮肤模块源码 编辑:程序博客网 时间:2024/05/09 00:05
As a talented student, your boss gave you a task. Given a text string, you should find out which letters appear most frequently.
Really simple, isn't it?
Input
The first line of the input is the number of test cases. Then some test cases followed.
Each test case contains only one line, indicating the string mentioned above.
You can assume there is only lower case letters in the string. The length of the string is more than 0 and no more than 100.
Output
You should output one line for each test case, indicating the most frequent letters. Please note there may be more than one such letter, so you should output all of them, and these letters should be in the same order as the alphabet, that is, 'a', 'b', 'c', 'd' ... 'z'.
Sample Input
2abcdatjucstju
Sample Output
ajtu
Hint
In the first sample test case, 'a' appears twice, while 'b','c','d' only appear once. So 'a' is the most frequent letter.
In the second sample test case, 't', 'j' and 'u' appear twice, so you should output them all, and 'j' should be the first.
Please note you should not output any unnecessary spaces or empty lines, or else you may get 'Presentation Error'.
#include<string>
#include<map>
using namespace std;
int main()
{
int t;
string s;
map<char,int>Set;
cin>>t;
while(t--)
{
cin>>s;
for(int i=0;i<s.size();++i)
Set[s[i]]++;
int max=0;
map<char,int>::iterator pos;
for(pos=Set.begin();pos!=Set.end();++pos)
if(pos->second > max)max=pos->second;
for(pos=Set.begin();pos!=Set.end();++pos)
if(pos->second==max)cout<<pos->first;
cout<<endl;
Set.clear();
}
return 0;
}
- TJU Counting Letters
- toj2468 Counting Letters
- 2468. Counting Letters
- LETTERS
- TJU 3474
- TJU Sequence
- TJU Vacation
- TJU Change
- TJU Antimonotonicity
- TJU Price
- TJU 4087
- Business Letters
- [POJ_1054]LETTERS
- 1154:LETTERS
- A--LETTERS
- Missing letters
- Missing letters
- Letters Gym
- OCP-1Z0-052-V8.02-166题
- 图片上按钮特效 热点链接(img map area)
- 华为机考回忆版(三:自己的)
- C++学习之旅——C++类型转换
- directx 编译书中带的源码出现无法解析的外部符号
- TJU Counting Letters
- VC操作文件、注册表
- C#专题 运算
- 【Mono】C# + Mono + Linux 编程初体验之 HelloWorld
- STL迭代器简介
- 一些简单的acm题
- 进程通信之共享内存
- 数组指针和指针数组的区别
- The big bang S7E1