題目:
https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=12&page=show_problem&problem=949
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| #include <iostream> #include <ctype.h> #include <string> #include <algorithm>
using namespace std;
int main(){ int arr[128+5] = {}; int n; cin >> n >> ws; while(n--){ string s; getline(cin, s); for(int i=0; i<s.length(); ++i){ if(isalpha(s[i])){ s[i] = toupper(s[i]); ++arr[(int)s[i]]; } } } int maxi = 0; for(int i=0; i<133; ++i){ maxi = max(maxi, arr[i]); } for(int i=maxi; i>=1; --i){ for(int j=0; j<133; ++j){ if(arr[j] == i) cout << (char)j << ' ' << i << '\n'; } } return 0; }
|