0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-10 07:38:49 +00:00
OI-codes/Luogu/P2108/P2108.cpp

55 lines
1.1 KiB
C++
Raw Normal View History

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