fs.cpp
#include <iostream>
#include <string>
using namespace std;
string encode( char s, int & len )
{
string pole[26] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..",
".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.",
"...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.." };
len = 4;
if( s == '_' )return "..--";
if( s == ',' ) return ".-.-";
if( s == '.' ) return "---.";
if( s == '?' ) return "----";
len = pole[ s - 'A' ].length();
return pole[ s - 'A' ];
}
char decode( const string & s )
{
string pole[26] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..",
".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.",
"...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.." };
int i;
for( i = 0; i < 26; i++ )
if( s == pole[i] )
return 'A' + i;
if( s == "..--" ) return '_';
if( s == ".-.-" ) return ',';
if( s == "---." ) return '.';
if( s == "----" ) return '?';
return 0;
}
int main()
{
string s;
while( getline(cin, s) )
{
string res;
int len = s.length();
int lenArr[len];
for( int i = 0; i < len; i++ )
res += encode( s[i], lenArr[i] );
int pos = 0;
for( int i = len-1; i >= 0; i-- )
{
string c = res.substr( pos, lenArr[i] );
pos += lenArr[i];
cout << decode( c );
}
cout << "\n";
}
return 0;
}
/**
AKADTOF_IBOETATUK_IJN
FENDSVTSLHW.EDATS,EULAY
TRDNWPLOEF
NTTTGAZEJUIIGDUZEHKUE
QEWOISE.EIVCAEFNRXTBELYTGD.
?EJHUT.TSMYGW?EJHOT
DSU.XFNCJEVE.OE_UJDXNO_YHU?VIDWDHPDJIKXZT?E
ADAWEKHZN,OTEATWRZMZN_IDWCZGTEPION
*/