美文网首页
poj1051 模拟

poj1051 模拟

作者: 暖昼氤氲 | 来源:发表于2019-11-02 20:10 被阅读0次
    /*
    Time:2019.11.2
    Author: Goven
    type:字符串处理 
    err:
    ref:
    */
    #include<iostream>
    #include<string>
    #include<map>
    #include<algorithm>
    using namespace std;
    
    int main()
    {
        map<char, string> morse, cnt;
        map<string, char> opMorse;
        morse['A'] = ".-"; morse['B'] = "-..."; morse['C'] = "-.-."; morse['D'] = "-..";
        morse['E'] = "."; morse['F'] = "..-."; morse['G'] = "--."; morse['H'] = "....";
        morse['I'] = ".."; morse['J'] = ".---"; morse['K'] = "-.-"; morse['L'] = ".-..";
        morse['M'] = "--"; morse['N'] = "-."; morse['O'] = "---"; morse['P'] = ".--.";
        morse['Q'] = "--.-"; morse['R'] = ".-."; morse['S'] = "..."; morse['T'] = "-";
        morse['U'] = "..-"; morse['V'] = "...-"; morse['W'] = ".--"; morse['X'] = "-..-";
        morse['Y'] = "-.--"; morse['Z'] = "--..";
        morse['_'] = "..--"; morse[','] = ".-.-"; morse['.'] = "---."; morse['?'] = "----";
        
        int a[105];
        for (map<char, string>::iterator it = morse.begin(); it != morse.end(); it++) {
            opMorse[it -> second] = it -> first;
        }
            
        int n;
        string s;
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> s;
            string t = "";
            int l = s.length();
            for (int j = 0; j < l; j++) {
                t += morse[s[j]];
                a[j] = morse[s[j]].length();
            }
            
            string res = "";
            int cnt = 0;
            for (int j = l - 1; j >= 0; j--) {
                res += opMorse[t.substr(cnt, a[j])];
                cnt += a[j];
            }
            cout << i << ": " << res << endl;   
        }
        return 0;
    }
    
    
    

    相关文章

      网友评论

          本文标题:poj1051 模拟

          本文链接:https://www.haomeiwen.com/subject/cxuhbctx.html