From 81b363881aebaf1de065211abab019bcc5bb3a41 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Tue, 20 Oct 2020 17:27:06 +0800 Subject: [PATCH] =?UTF-8?q?P2108=20=E5=AD=A6=E8=8B=B1=E8=AF=AD=20[50'=20Co?= =?UTF-8?q?de]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problem/P2108/P2108.cpp | 66 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 problem/P2108/P2108.cpp diff --git a/problem/P2108/P2108.cpp b/problem/P2108/P2108.cpp new file mode 100644 index 00000000..127dafb5 --- /dev/null +++ b/problem/P2108/P2108.cpp @@ -0,0 +1,66 @@ +#include + +using namespace std; + +int main() { + map m; + string s; + long long ans = 0, now = 0; + + 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; + m["seventeen"] = 17; + 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; + + while (cin >> s) { + if (s == "negative") { + cout << "-"; + } + else if (s == "hundred") { + ans += now; + ans *= 100; + now = 0; + } + else if (s == "thousand") { + ans += now; + ans *= 1000; + now = 0; + } + else if (s == "million") { + ans += now; + ans *= 1000000; + now = 0; + } + else { + now += m[s]; + } + } + if (now) { + ans += now; + } + cout << ans << endl; + return 0; +}