ZOJ-2971

来源:互联网 发布:淘宝开店怎么做代理商 编辑:程序博客网 时间:2024/06/11 22:56

比较简单的模拟题,英文数字转整数输出

#include<iostream>#include<sstream>#include<string>#include<map>using namespace std;int main(){map<string, int> mp;mp["zero"] = 0;mp["one"] = 1;mp["two"] = 2;mp["three"] = 3;mp["four"] = 4;mp["five"] = 5;mp["six"] = 6;mp["seven"] = 7;mp["eight"] = 8;mp["nine"] = 9;mp["ten"] = 10;mp["eleven"] = 11;mp["twelve"] = 12;mp["thirteen"] = 13;mp["fourteen"] = 14;mp["fifteen"] = 15;mp["sixteen"] = 16;mp["seventeen"] = 17;mp["eighteen"] = 18;mp["nineteen"] = 19;mp["twenty"] = 20;mp["thirty"] = 30;mp["forty"] = 40;mp["fifty"] = 50;mp["sixty"] = 60;mp["seventy"] = 70;mp["eighty"] = 80;mp["ninety"] = 90;int n;string line, word;cin >> n >> ws;while (n--){getline(cin, line);istringstream is(line);int thousand = 0, hundred = 0, million = 0, other = 0;while (is >> word){if (word == "and")continue;if (word == "hundred"){hundred = other * 100;other = 0;}else if (word == "thousand"){thousand = (hundred + other) * 1000;hundred = 0;other = 0;}else if (word == "million"){million = (hundred + other) * 1000000;hundred = 0;other = 0;}else{other += mp[word];}}cout << (million + thousand + hundred + other) << endl;}return 0;}


0 0
原创粉丝点击