zoj1068 P,MTHBGWB

  1. //zoj1068 P,MTHBGWB
  2. //Accepted 1068 C ++ 00:00.00 860K
  3. #include <cstdio>
  4. #include <string>
  5. #include <iostream>
  6. using namespace std;
  7. string morse[30]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--..","..--",".-.-","---.","----"};
  8. int key(char a)
  9. {
  10.        if (a=='_') return 26;
  11.        if (a==',') return 27;
  12.        if (a=='.') return 28;
  13.        if (a=='?') return 29;
  14.        return a-'A';
  15. }
  16.  
  17. void solve()
  18. {
  19.        string s,m;
  20.        int i,len[101];
  21.        cin >> s;
  22.        for (i=0; i<s.length(); ++i){
  23.               int k = key(s[i]);
  24.               len[i] = morse[k].length();
  25.               m += morse[k];
  26.        }
  27.        for (i=s.length()-1; i>=0; --i){
  28.               string t = m.substr(0,len[i]);
  29.               for (int j=0; j<30; ++j)
  30.                      if (t.compare(morse[j])==0){
  31.                             if (j==26) cout << '_';
  32.                             else if (j==27) cout << ',';
  33.                             else if (j==28) cout << '.';
  34.                             else if (j==29) cout << '?';
  35.                             else cout << (char)('A'+j);
  36.                      }
  37.               m.erase(0,len[i]);
  38.        }
  39.        cout << endl;
  40. }
  41. int main()
  42. {
  43. #ifdef ONLINE_JUDGE
  44. #else
  45.        freopen("1068.txt","r",stdin);
  46. #endif
  47.        int n;
  48.        while (cin >> n)
  49.               for (int i=1; i<=n; ++i){
  50.                      cout << i << ": ";
  51.                      solve();
  52.               }
  53. #ifdef ONLINE_JUDGE
  54. #else
  55.        fclose(stdin);
  56. #endif
  57.        return 0;
  58. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值