解题思路:
注意事项:
注意数组fg、max_len和t每次置零操作;(不懂可以去掉试试)
参考代码:
#include <cstdio> #include <cstdlib> #include <iostream> #include <cmath> #include <cctype> #include <cstring> #include <string> #include <stack> #include <algorithm> #include <functional> using namespace std; const int maxn=1001; char s[maxn]; int fg[26]; int main() { int n, max_len, t; scanf("%d", &n); while(n--) { scanf("%s", s); max_len = 0; t = 0; memset(fg, 0, sizeof(fg)); for(int i = 0, len = strlen(s); i < len; ++i) { fg[s[i]-'a']++; } for(int i = 0; i < 26; ++i) { if(fg[i] > max_len) { max_len = fg[i]; t = i; } } printf("%c %d\n", t+'a', max_len); } return 0; }
0.0分
1 人评分
数组输出 (C语言代码)--此题的题目描述有问题浏览:1817 |
P1001 (C语言代码)浏览:801 |
众数问题 (C语言代码)浏览:830 |
WU-格式化数据输出 (C语言代码)浏览:1755 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:544 |
数字游戏 (C++代码)浏览:1184 |
1048题解(读入回车问题)浏览:563 |
淘淘的名单 (C语言代码)浏览:1228 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:403 |
生日日数 (C语言代码)浏览:1502 |