P1603 斯诺登的密码

题目传送门

#include<bits/stdc++.h>

using namespace std;
//原始英文数字
// You are a three eight pig . 10964
unordered_map<string, int> _map = {{"zero",      0},
                                   {"one",       1},
                                   {"two",       4},
                                   {"three",     9},
                                   {"four",      16},
                                   {"five",      25},
                                   {"six",       36},
                                   {"seven",     49},
                                   {"eight",     64},
                                   {"nine",      81},
                                   {"ten",       0},
                                   {"eleven",    21},
                                   {"twelve",    44},
                                   {"thirteen",  69},
                                   {"fourteen",  96},
                                   {"fifteen",   25},
                                   {"sixteen",   56},
                                   {"seventeen", 89},
                                   {"eighteen",  24},
                                   {"nineteen",  61},
                                   {"twenty",    0},
                                   {"a",         1},
                                   {"both",      4},
                                   {"another",   1},
                                   {"first",     1},
                                   {"second",    4},
                                   {"third",     9}
};
string s;

const int N = 1010;
int a[N];
int idx;

int main() {
    //ctrl+d,或者ctrl+z结束
    while (cin >> s)
        if (_map[s]) a[idx++] = _map[s];

    //无脑的排序
    sort(a, a + idx);

    string res = "";
    for (int i = 0; i < idx; i++) {
        if (i > 0 && a[i] < 10) res += "0" + to_string(a[i]);
        else res += to_string(a[i]);
    }
    //第3个点需要特判,没任何数字,输出0,很坑……
    if (res != "") cout << res << endl;
    else cout << 0 << endl;
    return 0;
}
原文地址:https://www.cnblogs.com/littlehb/p/15571155.html