fs.cpp
//
// File: fs.cc
// Author: cteam008
//
// Created on October 19, 2013, 10:50 AM
//
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <iostream>
#include <map>
using namespace std;
//
//
//
int main(int argc, char** argv) {
int sizes[1000], idx,alphaSize = 30;
string line, m, result, s;
string morse[] = {
"..--",
"---.",
".-.-",
"----",
".-",
"-...",
"-.-.",
"-..",
".",
"..-.",
"--.",
"....",
"..",
".---",
"-.-",
".-..",
"--",
"-.",
"---",
".--.",
"--.-",
".-.",
"...",
"-",
"..-",
"...-",
".--",
"-..-",
"-.--",
"--.."
};
map<string, int> toChar;
toChar[morse[0]] = 95;
toChar[morse[1]] = 46;
toChar[morse[2]] = 44;
toChar[morse[3]] = 63;
for (int i = 4; i < alphaSize; i++) {
toChar[morse[i]] = i+61;
}
while (getline(cin, line)) {
m = "";
for (int i = 0; i < line.size(); i++) {
switch (line.at(i)) {
case 95:
m += morse[0];
sizes[i] = morse[0].size();
break;
case 46:
m += morse[1];
sizes[i] = morse[1].size();
break;
case 44:
m += morse[2];
sizes[i] = morse[2].size();
break;
case 63:
m += morse[3];
sizes[i] = morse[3].size();
break;
default:
m+= morse[line.at(i)-61];
sizes[i] = morse[line.at(i)-61].size();
}
}
result = "";
idx = 0;
for (int i = line.size()-1; i >= 0; i--) {
s = m.substr(idx, sizes[i]);
//reverse(s.begin(), s.end());
//printf("%d %d %s %c\n",idx, sizes[i],s.c_str(),char(toChar[s]));
result += char(toChar[s]);
idx+=sizes[i];
}
cout << result << endl;
}
return (EXIT_SUCCESS);
}
//AKADTOF_IBOETATUK_IJN