<span style="font-size:18px;"><strong>//统计字符 //给一个字符串(大写),请找出出现次数最多的大写英文字母 #pragma warning (disable:4996) #include <cstdio> #include <iostream> #include <cstring> using namespace std; int main() { int sum[27]; char z[2001], a; int i, k; scanf("%s", &z); memset(sum, 0, sizeof(sum)); for (i = 0; i < strlen(z); ++i) { sum[z[i] - 'A']++; } k = 0; for (i = 0; i < 27; ++i) { if (k < sum[i]) { k = sum[i]; a = i + 'A'; } } cout << a << " " << k << endl; return 0; }</strong></span>
<span style="font-size:18px;"><strong>#include <cstdio> #include <iostream> using namespace std; char Num[26] = { 'A','B','C','D','E','F','G','H','I','J','K', 'L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' }; char Count[26] = { 0 }; int main() { int k; char z[2001]; scanf("%s", &z); for (int i = 0; z[i] != '\0'; ++i) { if (z[i] == 'A') { Count[0]++; } if (z[i] == 'B') { Count[1]++; } if (z[i] == 'C') { Count[2]++; } if (z[i] == 'D') { Count[3]++; } if (z[i] == 'E') { Count[4]++; } if (z[i] == 'F') { Count[5]++; } if (z[i] == 'G') { Count[6]++; } if (z[i] == 'H') { Count[7]++; } if (z[i] == 'I') { Count[8]++; } if (z[i] == 'J') { Count[9]++; } if (z[i] == 'K') { Count[10]++; } if (z[i] == 'L') { Count[11]++; } if (z[i] == 'M') { Count[12]++; } if (z[i] == 'N') { Count[13]++; } if (z[i] == 'O') { Count[14]++; } if (z[i] == 'P') { Count[15]++; } if (z[i] == 'Q') { Count[16]++; } if (z[i] == 'R') { Count[17]++; } if (z[i] == 'S') { Count[18]++; } if (z[i] == 'T') { Count[19]++; } if (z[i] == 'U') { Count[20]++; } if (z[i] == 'V') { Count[21]++; } if (z[i] == 'W') { Count[22]++; } if (z[i] == 'X') { Count[23]++; } if (z[i] == 'Y') { Count[24]++; } if (z[i] == 'Z') { Count[25]++; } } int max = Count[0]; k = 0; for (int i = 1; i < 26; ++i) { if (Count[i] > max) { max = Count[i]; k = i; } } cout << Num[k] << " " << max << endl; return 0; }</strong></span>