-
//zoj1068 P,MTHBGWB
-
//Accepted 1068 C ++ 00:00.00 860K
-
#include <cstdio>
-
#include <string>
-
#include <iostream>
-
using namespace std;
-
string morse[30]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--..","..--",".-.-","---.","----"};
-
int key(char a)
-
{
-
if (a=='_') return 26;
-
if (a==',') return 27;
-
if (a=='.') return 28;
-
if (a=='?') return 29;
-
return a-'A';
-
}
-
-
void solve()
-
{
-
string s,m;
-
int i,len[101];
-
cin >> s;
-
for (i=0; i<s.length(); ++i){
-
int k = key(s[i]);
-
len[i] = morse[k].length();
-
m += morse[k];
-
}
-
for (i=s.length()-1; i>=0; --i){
-
string t = m.substr(0,len[i]);
-
for (int j=0; j<30; ++j)
-
if (t.compare(morse[j])==0){
-
if (j==26) cout << '_';
-
else if (j==27) cout << ',';
-
else if (j==28) cout << '.';
-
else if (j==29) cout << '?';
-
else cout << (char)('A'+j);
-
}
-
m.erase(0,len[i]);
-
}
-
cout << endl;
-
}
-
int main()
-
{
-
#ifdef ONLINE_JUDGE
-
#else
-
freopen("1068.txt","r",stdin);
-
#endif
-
int n;
-
while (cin >> n)
-
for (int i=1; i<=n; ++i){
-
cout << i << ": ";
-
solve();
-
}
-
#ifdef ONLINE_JUDGE
-
#else
-
fclose(stdin);
-
#endif
-
return 0;
-
}
zoj1068 P,MTHBGWB
最新推荐文章于 2017-05-15 21:56:19 发布