UVa 10222 – Decode the Mad man
BUET University had a professor who went crazy. He started saying some strange things, and no one could understand what he was teaching. Eventually, BUET University faced a dilemma: they couldn't let this professor continue teaching at the university. Suddenly, a student (probably a registered author of the UVA ACM chapter with a high ranking on the online judge) created a program that could decode what the professor was saying. After that, the professor returned to teaching normally, and everyone was happy. So, if you ever have the chance to visit BUET University and see a teacher speaking with a microphone equipped with speech recognition, don't be surprised. Because now your job is to write a similar program to decode the language of the crazy professor.
Sample Inputs/Outputs
Sample Input(s) | Sample Output(s) |
---|---|
EOF inputs: only one set of test data is included, which is the encoded message. This test data consists of one or more words. The letters are all lowercase.). | Based on the test data, output the decoded words. Thankfully, this task isn't difficult. You just need to replace each letter or symbol with the symbol on the second left key on the keyboard. There won't be any unreasonable situations, such as encoding the message "a", but "a" doesn't have a key to its left. Simply output spaces and line breaks as they are. |
k[r dyt i[o p ‘[nt ]y[jyd. | how are you i love program |
Thought Process
Use a Map to record the corresponding value for each character. Use \' to represent a single quote, and \ for a backslash.
Sample Code-ZeroJudge E578: Decode the Mad Man
#include <iostream>
#include <map>
using namespace std;
int main() {
string str;
map<char, char>MAP;
MAP['2'] = '`';
MAP['3'] = '1';
MAP['4'] = '2';
MAP['5'] = '3';
MAP['6'] = '4';
MAP['7'] = '5';
MAP['8'] = '6';
MAP['9'] = '7';
MAP['0'] = '8';
MAP['-'] = '9';
MAP['='] = '0';
MAP['e'] = 'q';
MAP['r'] = 'w';
MAP['t'] = 'e';
MAP['y'] = 'r';
MAP['u'] = 't';
MAP['i'] = 'y';
MAP['o'] = 'u';
MAP['p'] = 'i';
MAP['['] = 'o';
MAP[']'] = 'p';
MAP['\\'] = '[';
MAP['d'] = 'a';
MAP['f'] = 's';
MAP['g'] = 'd';
MAP['h'] = 'f';
MAP['j'] = 'g';
MAP['k'] = 'h';
MAP['l'] = 'j';
MAP[';'] = 'k';
MAP['\''] = 'l';
MAP['c'] = 'z';
MAP['v'] = 'x';
MAP['b'] = 'c';
MAP['n'] = 'v';
MAP['m'] = 'b';
MAP[','] = 'n';
MAP['.'] = 'm';
MAP['/'] = ',';
MAP[' '] = ' ';
while (getline(cin, str))
{
for (int i = 0; i<str.length(); i++)
{
cout << MAP[str[i]];
}
cout << "\n";
}
}
//ZeroJudge E578
//Dr. SeanXD