UVa 10082 – WERTYU
A common mistake when typing is not placing your fingers in the correct position, but rather one position to the right. This can result in "Q" being typed as "W," "J" as "K," and so on. Your task is to correct the mistyped words.
Sample Inputs/Outputs
Sample Input(s) | Sample Output(s) |
---|---|
The input consists of several lines, each potentially containing numbers, whitespace characters, uppercase English letters (excluding Q, A, Z), and punctuation marks (excluding backticks). | For each character in each line, please output the character that is one position to the left on the keyboard (as shown in the image above). However, if the input contains whitespace characters, please output whitespace characters as well. |
O S, GOMR YPFSU/ URD. ,U [JPMR MI,NRT OD 8346333 | I AM FINE TODAY. YES, MY PHONE NUMBER IS 7235222 |
Thought Process
You can use a map to build a reference. Just note that \ and ' are special characters, so you'll need to represent them differently: \ as \\ and ' as \'.
Sample Code-ZeroJudge C054: WERTYU
#include <iostream>
#include <map>
using namespace std;
int main() {
map<char, char>MAP;
MAP['`'] = '`';
MAP['1'] = '`';
MAP['2'] = '1';
MAP['3'] = '2';
MAP['4'] = '3';
MAP['5'] = '4';
MAP['6'] = '5';
MAP['7'] = '6';
MAP['8'] = '7';
MAP['9'] = '8';
MAP['0'] = '9';
MAP['-'] = '0';
MAP['='] = '-';
MAP['Q'] = 'Q';
MAP['W'] = 'Q';
MAP['E'] = 'W';
MAP['R'] = 'E';
MAP['T'] = 'R';
MAP['Y'] = 'T';
MAP['U'] = 'Y';
MAP['I'] = 'U';
MAP['O'] = 'I';
MAP['P'] = 'O';
MAP['['] = 'P';
MAP[']'] = '[';
MAP['\\'] = ']';
MAP['A'] = 'A';
MAP['S'] = 'A';
MAP['D'] = 'S';
MAP['F'] = 'D';
MAP['G'] = 'F';
MAP['H'] = 'G';
MAP['J'] = 'H';
MAP['K'] = 'J';
MAP['L'] = 'K';
MAP[';'] = 'L';
MAP['\''] = ';';
MAP['Z'] = 'Z';
MAP['X'] = 'Z';
MAP['C'] = 'X';
MAP['V'] = 'C';
MAP['B'] = 'V';
MAP['N'] = 'B';
MAP['M'] = 'N';
MAP[','] = 'M';
MAP['.'] = ',';
MAP['/'] = '.';
MAP[' '] = ' ';
string str;
while (getline(cin, str))
{
for (int i = 0; i<str.length(); i++)
{
cout << MAP[str[i]];
}
cout << "\n";
}
}
//ZeroJudge C054
//Dr. SeanXD