题干
C++实现
#include <stdio.h>
#include <map>
using namespace std;
int main() {
char strArr[200] = { 0 };
map<char, char> toCorrect = {
{' ',' '},
{'2','1'},{'3','2'},{'4','3'},{'5','4'},{'6','5'},{'7','6'},{'8','7'},{'9','8'},{'0','9'},{'-','0'},{'=','-'},
{'W','Q'},{'E','W'},{'R','E'},{'T','R'},{'Y','T'},{'U','Y'},{'I','U'},{'O','I'},{'P','O'},{'[','P'},{']','['},
{'S','A'},{'D','S'},{'F','D'},{'G','F'},{'H','G'},{'J','H'},{'K','J'},{'L','K'},{';','L'},{'\'',';'},
{'X','Z'},{'C','X'},{'V','C'},{'B','V'},{'N','B'},{'M','N'},{',','M'},{'.',','},{'/','.'}
};
while (fgets(strArr, 200, stdin) != NULL) {
for (int i = 0; strArr[i] != '\0'; ++i) {
if (strArr[i] == '\n') {
strArr[i] = '\0';
}
strArr[i] = toCorrect[strArr[i]];
}
printf("%s\n", strArr);
}
return 0;
}