fs.cpp
//
// File: fs.cc
// Author: cteam030
//
// Created on October 19, 2013, 11:06 AM
//
#include <stdlib.h>
#include <iostream>
#include <string>
#include <map>
#include <sstream>
using namespace std;
//
//
//
int main(int argc, char** argv) {
map<char, string> t2m;
map<string, string> m2t;
t2m['A'] = ".-";
t2m['B'] = "-...";
t2m['C'] = "-.-.";
t2m['D'] = "-..";
t2m['E'] = ".";
t2m['F'] = "..-.";
t2m['G'] = "--.";
t2m['H'] = "....";
t2m['I'] = "..";
t2m['J'] = ".---";
t2m['K'] = "-.-";
t2m['L'] = ".-..";
t2m['M'] = "--";
t2m['N'] = "-.";
t2m['O'] = "---";
t2m['P'] = ".--.";
t2m['Q'] = "--.-";
t2m['R'] = ".-.";
t2m['S'] = "...";
t2m['T'] = "-";
t2m['U'] = "..-";
t2m['V'] = "...-";
t2m['W'] = ".--";
t2m['X'] = "-..-";
t2m['Y'] = "-.--";
t2m['Z'] = "--..";
t2m['_'] = "..--";
t2m[','] = ".-.-";
t2m['.'] = "---.";
t2m['?'] = "----";
m2t[".-"] = "A";
m2t["-..."] = "B";
m2t["-.-."] = "C";
m2t["-.."] = "D";
m2t["."] = "E";
m2t["..-."] = "F";
m2t["--."] = "G";
m2t["...."] ="H" ;
m2t[".."] = "I";
m2t[".---"] = "J";
m2t["-.-"] = "K";
m2t[".-.."] = "L";
m2t["--"] = "M";
m2t["-."] = "N";
m2t["---"] = "O";
m2t[".--."] = "P";
m2t["--.-"] = "Q";
m2t[".-."] = "R";
m2t["..."] = "S";
m2t["-"] = "T";
m2t["..-"] = "U";
m2t["...-"] = "V";
m2t[".--"] = "W";
m2t["-..-"] = "X";
m2t["-.--"] = "Y";
m2t["--.."] = "Z";
m2t["..--"] = "_";
m2t[".-.-"] = ",";
m2t["---."] = ".";
m2t["----"] = "?";
string line;
while(cin >> line) {
stringstream morse;
morse.clear();
int pos[line.length()];
for(size_t i=0; i<line.length();i++) {
morse << t2m[line[i]];
pos[i] = t2m[line[i]].length();
}
int off=0;
string sMorse = morse.str();
stringstream out;
out.clear();
for(int i=line.length()-1; i>=0; i--) {
string tmp = sMorse.substr(off, pos[i]);
out << m2t[tmp];
off += pos[i];
}
cout << out.str() << "\n";
}
return (0);
}