解题思路:
注意事项:
注意数组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 人评分
WU-printf基础练习2 (C++代码)浏览:2000 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:536 |
C语言程序设计教程(第三版)课后习题9.2 (C语言代码)浏览:556 |
C语言程序设计教程(第三版)课后习题9.8 (C语言代码)浏览:664 |
C语言程序设计教程(第三版)课后习题5.5 (C语言代码)浏览:552 |
printf基础练习2 (C语言代码)浏览:503 |
链表数据求和操作 (C语言代码)浏览:941 |
简单的a+b (C语言代码)浏览:628 |
盐水的故事 (C语言代码)浏览:1524 |
简单的a+b (C语言代码)浏览:635 |