poj1051 模拟

/*
Time:2019.11.2
Author: Goven
type:字符串处理 
err:
ref:
*/
#include
#include
#include
#include
using namespace std;

int main()
{
    map morse, cnt;
    map 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::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 模拟)