Advertisement
Imran2544

[Uva 11223] O: Dah Dah Dah

Dec 30th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     map<string, char>r;
  7.     r[".-"] = 'A', r["-..."] = 'B', r["-.-."] = 'C';
  8.     r["-.."] = 'D', r["."] = 'E', r["..-."] = 'F';
  9.     r["--."] = 'G', r["...."] = 'H', r[".."] = 'I';
  10.     r[".---"] = 'J', r["-.-"] = 'K', r[".-.."] = 'L';
  11.     r["--"] = 'M', r["-."] = 'N', r["---"] = 'O';
  12.     r[".--."] = 'P', r["--.-"] = 'Q', r[".-."] = 'R';
  13.     r["..."] = 'S', r["-"] = 'T', r["..-"] = 'U';
  14.     r["...-"] = 'V', r[".--"] = 'W', r["-..-"] = 'X';
  15.     r["-.--"] = 'Y', r["--.."] = 'Z', r["-----"] = '0';
  16.     r[".----"] = '1', r["..---"] = '2', r["...--"] = '3';
  17.     r["....-"] = '4', r["....."] = '5', r["-...."] = '6';
  18.     r["--..."] = '7', r["---.."] = '8', r["----."] = '9';
  19.     r[".-.-.-"] = '.', r["--..--"] = ',', r["..--.."] = '?';
  20.     r[".----."] = '\'', r["-.-.--"] = '!', r["-..-."] = '/';
  21.     r["-.--."] = '(', r["-.--.-"] = ')', r[".-..."] = '&';
  22.     r["---..."] = ':', r["-.-.-."] = ';', r["-...-"] = '=';
  23.     r[".-.-."] = '+', r["-....-"] = '-', r["..--.-"] = '_';
  24.     r[".-..-."] = '\"', r[".--.-."] = '@';
  25.     int t, ca=1;
  26.     cin>>t;
  27.     string in;
  28.     cin.ignore(100, '\n');
  29.     while (t--) {
  30.         cout<<"Message #"<<ca++<<endl;
  31.         //getchar();
  32.         getline(cin, in);
  33.         int cnt=0, l=in.length();
  34.         for (int i=0; in[i]; i++) {
  35.             if (isspace(in[i])) {
  36.                 if (cnt==1) {
  37.                     cout<<" ";
  38.                     cnt=0;
  39.                 }
  40.                 else cnt++;
  41.                 continue;
  42.             }
  43.             string s="";
  44.             int j=i;
  45.             while (!isspace(in[j]) && j<l) {
  46.                 s.push_back(in[j++]);
  47.             }
  48.             cout<<r[s];
  49.             cnt=0, i=j-1;
  50.         }
  51.         cout<<endl;
  52.         if (t!=0)
  53.             cout<<endl;
  54.     }
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement