Advertisement
Nayeemzaman

Untitled

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