A common typing error is to place the hands on the keyboard one row to the right of the correct position. So "Q" is typed as "W" and "J" is typed as "K" and so on. You are to decode a message typed in this manner.
Input consists of several lines of text. Each line may contain digits, spaces, upper case letters (except Q, A, Z), or punctuation shown above [except back-quote (`)]. Keys labelled with words [Tab, BackSp, Control, etc.] are not represented in the input. You are to replace each letter or punction symbol by the one immediately to its left on the QWERTY keyboard shown above. Spaces in the input should be echoed in the output.
Sample Input
O S, GOMR YPFSU/
Output for Sample Input
I AM FINE TODAY.
出處: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1023
這題就是把每個input的鍵對應到左邊的鍵就對了。
以下是c++程式碼:
#include <iostream> #include <map> using namespace std; int main() { map<char, char> table; string input; table['1'] = '`'; table['2'] = '1'; table['3'] = '2'; table['4'] = '3'; table['5'] = '4'; table['6'] = '5'; table['7'] = '6'; table['8'] = '7'; table['9'] = '8'; table['0'] = '9'; table['-'] = '0'; table['='] = '-'; table['W'] = 'Q'; table['E'] = 'W'; table['R'] = 'E'; table['T'] = 'R'; table['Y'] = 'T'; table['U'] = 'Y'; table['I'] = 'U'; table['O'] = 'I'; table['P'] = 'O'; table['['] = 'P'; table[']'] = '['; table['\\'] = ']'; table['S'] = 'A'; table['D'] = 'S'; table['F'] = 'D'; table['G'] = 'F'; table['H'] = 'G'; table['J'] = 'H'; table['K'] = 'J'; table['L'] = 'K'; table[';'] = 'L'; table['\''] = ';'; table['X'] = 'Z'; table['C'] = 'X'; table['V'] = 'C'; table['B'] = 'V'; table['N'] = 'B'; table['M'] = 'N'; table[','] = 'M'; table['.'] = ','; table['/'] = '.'; table[' '] = ' '; while (getline(cin, input)) { for (int i=0; i<input.length(); i++) cout << table[input[i]]; cout << endl; } return 0; }
沒有留言:
張貼留言