Advertisement
Nayeemzaman

Untitled

Apr 6th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.11 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     map<string,char>ch;
  7.  
  8.     ch[".-"] = 'A';
  9.     ch["-..."] = 'B';
  10.     ch["-.-."] = 'C';
  11.     ch["-.."] = 'D';
  12.     ch["."] = 'E';
  13.     ch["..-."] = 'F';
  14.     ch["--."] = 'G';
  15.     ch["...."] = 'H';
  16.     ch[".."] = 'I';
  17.     ch[".---"] = 'J';
  18.     ch["-.-"] = 'K';
  19.     ch[".-.."] = 'L';
  20.     ch["--"] = 'M';
  21.     ch["-."] = 'N';
  22.     ch["---"] = '0';
  23.     ch[".--."] = 'P';
  24.     ch["--.-"] = 'Q';
  25.     ch[".-."] = 'R';
  26.     ch["..."] = 'S';
  27.     ch["-"] = 'T';
  28.     ch["..-"] = 'U';
  29.     ch["...-"] = 'V';
  30.     ch[".--"] = 'W';
  31.     ch["-..-"] = 'X';
  32.     ch["-.--"] = 'Y';
  33.     ch["--.."] = 'Z';
  34.     ch["-----"] = '0';
  35.     ch[".----"] = '1';
  36.     ch["..---"] = '2';
  37.     ch["...--"] = '3';
  38.     ch["....-"] = '4';
  39.     ch["....."] = '5';
  40.     ch["-...."] = '6';
  41.     ch["--..."] = '7';
  42.     ch["---.."] = '8';
  43.     ch["----."] = '9';
  44.     ch[".-.-.-"] = '.';
  45.     ch["--..--"] = ',';
  46.     ch["..--.."] = '?';
  47.     ch[".----."] = '\'';
  48.     ch["-.-.--"] = '!';
  49.     ch["-..-."] = '/';
  50.     ch["-.--."] = '(';
  51.     ch["-.--.-"] = ')';
  52.     ch[".-..."] = '&';
  53.     ch["---..."] = ':';
  54.     ch["-.-.-."] = ';';
  55.     ch["-...-"] = '=';
  56.     ch[".-.-."] = '+';
  57.     ch["-....-"] = '-';
  58.     ch["..--.-"] = '_';
  59.     ch[".-..-."] = '\"';
  60.     ch[".--.-."] = '@';
  61.  
  62.     int t;
  63.     string msg;
  64.     cin >> t;
  65.  
  66.     getchar();
  67.     for(int i=1; i<=t; i++)
  68.     {
  69.         getline(cin,msg);
  70.  
  71.         int l = msg.length(),ct=0;
  72.  
  73.         cout << "Message #" << i << endl;
  74.         for(int j=0; j<l; j++)
  75.         {
  76.             if(msg[j] == ' ')
  77.             {
  78.                 if(ct == 1)
  79.                 {
  80.                     cout << ' ';
  81.                     ct = 0;
  82.                 }
  83.                 else ct++;
  84.  
  85.                 continue;
  86.             }
  87.             string x;
  88.             int k = j;
  89.             while(msg[k] != ' ' && k<l)
  90.             {
  91.                 x += msg[k];
  92.                 k++;
  93.             }
  94.             ct =0;
  95.             j  = k-1;
  96.             cout << ch[x];
  97.  
  98.         }
  99.         cout << endl;
  100.         if(i < t)
  101.             cout << endl;
  102.     }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement