该题硬写即可,就是有点麻烦。直接附上代码了
#include <iostream>
#include <string.h>
using namespace std;
int a[9];
int main()
{
char b[50];
cin >> b;
int x = strlen(b);
for (int i = 0; i <= x - 1; i++)
{
if (b[i] == '`' || b[i] == '1' || b[i] == 'q' || b[i] == 'Q' || b[i] == 'a' || b[i] == 'A' || b[i] == 'z' || b[i] == 'Z')
a[1] += 1;
if (b[i] == '2'|| b[i] == 'w' || b[i] == 'W' || b[i] == 's' || b[i] == 'S' || b[i] == 'x' || b[i] == 'X')
a[2] += 1;
if (b[i] == '3'|| b[i] == 'E' || b[i] == 'e' || b[i] == 'd' || b[i] == 'D' || b[i] == 'c' || b[i] == 'C')
a[3] += 1;
if (b[i] == '4' || b[i] == '5' || b[i] == 'r' || b[i] == 'R' || b[i] == 'F' || b[i] == 'f' || b[i] == 'v' || b[i] == 'V' || b[i] == 't' || b[i] == 'T' || b[i] == 'g' || b[i] == 'G' || b[i] == 'b' || b[i] == 'B')
a[4] += 1;
if (b[i] == '6' || b[i] == '7' || b[i] == 'Y' || b[i] == 'y' || b[i] == 'H' || b[i] == 'h' || b[i] == 'n' || b[i] == 'N' || b[i] == 'U' || b[i] == 'u' || b[i] == 'J' || b[i] == 'j' || b[i] == 'M' || b[i] == 'm')
a[5] += 1;
if (b[i] == '8' || b[i] == 'i' || b[i] == 'I' || b[i] == 'k' || b[i] == 'K' || b[i] == ',')
a[6] += 1;
if (b[i] == '9' || b[i] == 'o' || b[i] == 'O' || b[i] == 'l' || b[i] == 'L' || b[i] == '.')
a[7] += 1;
if (b[i] == '0' || b[i] == '-' || b[i] == '=' || b[i] == '[' || b[i] == ']' || b[i] == 'p' || b[i] == 'P' || b[i] == ';' || b[i] == '\'' || b[i] == '/')
a[8] += 1;
}
for (int i = 1; i <= 7; i++)
cout << a[i] << '\n';
cout<<a[8];
return 0;
}