Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2164
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- int tc;
- cin >> tc;
- getchar();
- for(int tr = 1; tr <= tc; tr++){
- map<string, char> m;
- m[".-"] = 'A';
- m["-..."] = 'B';
- m["-.-."] = 'C';
- m["-.."] = 'D';
- m["."] = 'E';
- m["..-."] = 'F';
- m["--."] = 'G';
- m["...."] = 'H';
- m[".."] = 'I';
- m[".---"] = 'J';
- m["-.-"] = 'K';
- m[".-.."] = 'L';
- m["--"] = 'M';
- m["-."] = 'N';
- m["---"] = 'O';
- m[".--."] = 'P';
- m["--.-"] = 'Q';
- m[".-."] = 'R';
- m["..."] = 'S';
- m["-"] = 'T';
- m["..-"] = 'U';
- m["...-"] = 'V';
- m[".--"] = 'W';
- m["-..-"] = 'X';
- m["-.--"] = 'Y';
- m["--.."] = 'Z';
- m["-----"] = '0';
- m[".----"] = '1';
- m["..---"] = '2';
- m["...--"] = '3';
- m["....-"] = '4';
- m["....."] = '5';
- m["-...."] = '6';
- m["--..."] = '7';
- m["---.."] = '8';
- m["----."] = '9';
- m[".-.-.-"] = '.';
- m["--..--"] = ',';
- m["..--.."] = '?';
- m[".----."] = '\'';
- m["-.-.--"] = '!';
- m["-..-."] = '/';
- m["-.--."] = '(';
- m["-.--.-"] = ')';
- m[".-..."] = '&';
- m["---..."] = ':';
- m["-.-.-."] = ';';
- m["-...-"] = '=';
- m[".-.-."] = '+';
- m["-....-"] = '-';
- m["..--.-"] = '_';
- m[".-..-."] = '"';
- m[".--.-."] = '@';
- string morse;
- getline(cin, morse);
- vector<char> message;
- char c_morse[morse.length()+1];
- strcpy(c_morse, morse.c_str());
- char *word;
- word = strtok(c_morse, " ");
- while(word){
- string str = word;
- map<string, char>::iterator it = m.find(str);
- if(it != m.end()) message.push_back(it->second);
- word = strtok(NULL, " ");
- }
- printf("Message #%d\n", tr);
- int j = 0;
- for(int i = 0; i < morse.length(); i++){
- if(morse[i] == ' '){
- cout << message[j];
- if((i+1) != morse.length() && morse[i+1] == ' '){
- cout << " ";
- i++;
- }
- j++;
- }
- }
- cout << message[j] << endl;
- if(tr != tc) cout << endl;
- //.--- --- -... -.. --- -. . ..--.. ..-. .. -. . -.-.--
- }//testcase
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement