标签:
题目:给你一句话,统计里面出现最多的字母,有多个按字典序输出。
分析:简单题。直接统计即可。
说明:注意输入格式。
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <cmath> using namespace std; int main() { int n,count[27]; char buf[202]; while (~scanf("%d",&n)) { getchar(); while (n --) { gets(buf); for (int i = 0; i < 27; ++ i) count[i] = 0; for (int i = 0; buf[i]; ++ i) { if (buf[i] >= 'A' && buf[i] <= 'Z') ++ count[buf[i]-'A']; if (buf[i] >= 'a' && buf[i] <= 'z') ++ count[buf[i]-'a']; } int max = 0; for (int i = 0; i < 27; ++ i) if (max < count[i]) max = count[i]; for (int i = 0; i < 27; ++ i) if (max == count[i]) printf("%c",'a'+i); printf("\n"); } } return 0; }
标签:
原文地址:http://blog.csdn.net/mobius_strip/article/details/46622581