PAT1042 字符统计 (20 分)
生活随笔
收集整理的這篇文章主要介紹了
PAT1042 字符统计 (20 分)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目
代碼
#include<iostream> #include<string> using namespace std; int main() {int count[26] = { 0 };char c;//輸入并計算重復次數while (1){c = getchar();if (c == '\n')//結束{break;}else if (c >= 'a'&&c <= 'z'){count[c - 'a']++;}else if (c >= 'A'&&c <= 'Z'){count[c - 'A']++;}}//找最大int maxIndex = 0;int i;for (i = 0; i < 26; i++){if (count[i] > count[maxIndex]){maxIndex = i;}}char maxChar = 'a' + maxIndex;cout << maxChar << ' ' << count[maxIndex];//system("pause");return 0; }總結
以上是生活随笔為你收集整理的PAT1042 字符统计 (20 分)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PAT1041 考试座位号 (15 分)
- 下一篇: PAT1043 输出PATest (20