本地调试和测试点答案相同,但是除了0其他全部WA

P1603 斯诺登的密码

Wuyan7 @ 2024-06-24 13:10:02

#include <bits/stdc++.h>
using namespace std;

int idx;
char is[2];
string s, ans;
vector<string> lst;

int main() {
    map<string, int> dic = {
        {"one", 1}, {"another", 1}, {"two", 2}, {"three", 3}, {"four", 4}, {"five", 5}, 
        {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}, {"ten", 10}, {"eleven", 11},
        {"twelve", 12}, {"thirteen", 13}, {"fourteen", 14}, {"fifteen", 15}, {"sixteen", 16},
        {"seventeen", 17}, {"eighteen", 18}, {"nineteen", 19}, {"twenty", 20}, {"a", 1},
        {"both", 2}, {"first", 1}, {"second", 2}, {"third", 3}
    };
    while (cin >> s) if (dic.count(s))  // 将要组合的数格式化后放入lst
        {sprintf(is, "%02d", dic[s] * dic[s] % 100);  lst.push_back(is);}
    sort(lst.begin(), lst.end());       // 字典序排序,由于格式化了,"07"比"18"小,和整数排序一样

    for (auto x :lst) ans += x;
    while (ans[0] == '0') ans.erase(0, 1);
    cout << (ans.empty() ?"0" :ans);
}

|