0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-30 18:56:26 +00:00

P2108 学英语

R52635743
This commit is contained in:
Baoshuo Ren 2021-07-08 17:49:28 +08:00 committed by Baoshuo Ren
parent 25ce10f451
commit caf0293b04
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -3,64 +3,52 @@
using namespace std; using namespace std;
int main() { int main() {
string s;
map<string, int> m; map<string, int> m;
string s; int ans = 0, tmp = 0, w = 1;
long long ans = 0, now = 0; m["one"] = 1;
m["two"] = 2;
m["one"] = 1; m["three"] = 3;
m["two"] = 2; m["four"] = 4;
m["three"] = 3; m["five"] = 5;
m["four"] = 4; m["six"] = 6;
m["five"] = 5; m["seven"] = 7;
m["six"] = 6; m["eight"] = 8;
m["seven"] = 7; m["nine"] = 9;
m["eight"] = 8; m["ten"] = 10;
m["nine"] = 9; m["eleven"] = 11;
m["ten"] = 10; m["twelve"] = 12;
m["eleven"] = 11; m["thirteen"] = 13;
m["twelve"] = 12; m["fourteen"] = 14;
m["thirteen"] = 13; m["fifteen"] = 15;
m["fourteen"] = 14; m["sixteen"] = 16;
m["fifteen"] = 15;
m["sixteen"] = 16;
m["seventeen"] = 17; m["seventeen"] = 17;
m["eighteen"] = 18; m["eighteen"] = 18;
m["nineteen"] = 19; m["nineteen"] = 19;
m["twenty"] = 20; m["twenty"] = 20;
m["thirty"] = 30; m["thirty"] = 30;
m["forty"] = 40; m["forty"] = 40;
m["fifty"] = 50; m["fifty"] = 50;
m["sixty"] = 60; m["sixty"] = 60;
m["seventy"] = 70; m["seventy"] = 70;
m["eighty"] = 80; m["eighty"] = 80;
m["ninety"] = 90; m["ninety"] = 90;
while (cin >> s) { while (cin >> s) {
if (s == "negative") { if (s == "negative") {
cout << "-"; w = -1;
} } else if (s == "hundred") {
else if (s == "hundred") { tmp *= 100;
ans += now; } else if (s == "thousand") {
ans *= 100; ans += tmp * 1000;
now = 0; tmp = 0;
} } else if (s == "million") {
else if (s == "thousand") { ans += tmp * 1000000;
ans += now; tmp = 0;
ans *= 1000; } else {
now = 0; tmp += m[s];
}
else if (s == "million") {
ans += now;
ans *= 1000000;
now = 0;
}
else {
now += m[s];
} }
} }
if (now) { ans += tmp;
ans += now; cout << w * ans << endl;
}
cout << ans << endl;
return 0; return 0;
} }