直接上代码:
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(){
ios::sync_with_stdio(false); //输入输出加速
map<char, char> mapKeyboard;
long long iLength, i;
string sInput, sAns;
mapKeyboard['Q'] = 'Q';
mapKeyboard['W'] = 'Q';
mapKeyboard['E'] = 'W';
mapKeyboard['R'] = 'E';
mapKeyboard['T'] = 'R';
mapKeyboard['Y'] = 'T';
mapKeyboard['U'] = 'Y';
mapKeyboard['I'] = 'U';
mapKeyboard['O'] = 'I';
mapKeyboard['P'] = 'O';
mapKeyboard['['] = 'P';
mapKeyboard[']'] = '[';
mapKeyboard['A'] = 'A';
mapKeyboard['S'] = 'A';
mapKeyboard['D'] = 'S';
mapKeyboard['F'] = 'D';
mapKeyboard['G'] = 'F';
mapKeyboard['H'] = 'G';
mapKeyboard['J'] = 'H';
mapKeyboard['K'] = 'J';
mapKeyboard['L'] = 'K';
mapKeyboard[';'] = 'L';
mapKeyboard['\''] = ';';
mapKeyboard['Z'] = 'Z';
mapKeyboard['X'] = 'Z';
mapKeyboard['C'] = 'X';
mapKeyboard['V'] = 'C';
mapKeyboard['B'] = 'V';
mapKeyboard['N'] = 'B';
mapKeyboard['M'] = 'N';
mapKeyboard[','] = 'M';
mapKeyboard['.'] = ',';
mapKeyboard['/'] = '.';
mapKeyboard['\\']=']';
mapKeyboard[' '] = ' ';
mapKeyboard['`'] = '`';
mapKeyboard['1'] = '`';
mapKeyboard['2'] = '1';
mapKeyboard['3'] = '2';
mapKeyboard['4'] = '3';
mapKeyboard['5'] = '4';
mapKeyboard['6'] = '5';
mapKeyboard['7'] = '6';
mapKeyboard['8'] = '7';
mapKeyboard['9'] = '8';
mapKeyboard['0'] = '9';
mapKeyboard['-'] = '0';
mapKeyboard['='] = '-';
while (getline(cin, sInput)){
iLength = sInput.length();
for (i = 0; i < iLength; ++i){
sAns += mapKeyboard[sInput[i]]; //向答案串中按照对应关系添加字符
}
cout << sAns << endl;
sAns = "";
}
return 0;
}