想不到哪错了有大佬可以看看吗,最后一个数据不对

P1603 斯诺登的密码

shouyushen @ 2018-05-27 23:46:47

#include<bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    map<string,int> number= { { "one",1},{"two",4},{"three",9},{"four",16},{"five",25},{"six",36},{"seven",49},{"eight",64},{"nine",81},{"eleven",21},{"twelve",44},{"thirteen",69},{"fourteen",96},{"fifteen",25},{"sixteen",56},{"seventeen",89},{"eighteen",24},{"nineteen",61},{"a",1},{"both",4},{"another",9},{"first",1},{"second",4},{"third",9}};
    regex reg("\\b\(\\w+)\\b");
    string sentence;
    getline(cin, sentence);
    sregex_iterator iter(sentence.begin(), sentence.end(), reg),end;
    vector<int> ans;
    for (; iter != end; ++iter) {
        auto str = iter->str(1);
        auto map_iter = number.find(str);
        if (map_iter != number.end())
            ans.push_back(map_iter->second);
    }
    sort(ans.begin(), ans.end());
    if (!ans.empty()) {
        cout << ans.front();
        for (auto ans_iter = ans.begin() + 1; ans_iter != ans.end(); ++ans_iter) {
            cout << setw(2) << setfill('0') << *ans_iter;
        }
    }
    else cout << "0";
    return 0;
}

by lovecpp @ 2018-05-28 07:29:50

zero?


|