fs.cpp
#include <stdio.h>
#include <map>
#include <string>
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;
string mm[31] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.",
"....", "..", ".---", "-.-", ".-..", "--", "-.",
"---", ".--.", "--.-", ".-.", "...", "-", "..-",
"...-", ".--", "-..-", "-.--", "--..",
"..--", ".-.-", "---.", "----"
};
map<string, int> mr;
int main() {
for ( int i = 0; i < 30; ++i )
mr[string(mm[i])] = i;
string str;
while ( getline(cin, str) ) {
string tmp;
vector <int> tmp2(str.size());
for ( int i = 0; i < str.size(); ++i ) {
int p;
if ( str[i] >= 'A' && str[i] <= 'Z' )
p = str[i] - 'A';
else if ( str[i] == '_' )
p = 26;
else if ( str[i] == ',' )
p = 27;
else if ( str[i] == '.' )
p = 28;
else if ( str[i] == '?' )
p = 29;
else {
printf("AAAAAAAAAAAAAAAAAAAAAAAAAAAArgh....\n");
return 1;
}
tmp += mm[p];
tmp2[i] = mm[p].size();
}
// cout << tmp << endl;
int last = 0;
int i = tmp2.size()-1;
while ( last < tmp.size() ) {
char str2[10];
strncpy(str2, tmp.c_str()+last, tmp2[i]);
str2[tmp2[i]] = 0;
int c = mr[string(str2)];
// printf("str2=%s c=%d tmp2[i]=%d\n", str2, c, tmp2[i]);
if ( c < 26 )
putchar(c+'A');
else if ( c == 26 )
putchar('_');
else if ( c == 27 )
putchar(',');
else if ( c == 28 )
putchar('.');
else if ( c == 29 )
putchar('?');
last += tmp2[i];
--i;
}
putchar('\n');
}
return 0;
}