关键是搞清楚,one hundred million这样的结构表达的是1 * 100 * 1000000, 而one million one hundred这样的结构表达的是1000000 + 100,也就是说,数量级大的在数量级小的之前的时候,其实是一个加法关系。而小的在前的时候,则是乘法关系。
#include<iostream>
#include<map>
#include<string>
#include<stack>
using namespace std;
bool cmps(string &s1, string &s2){
if (s1 == "ones")
return true;
if (s1 == "million")
if (s2 == "thousand" || s2 == "hundred")
return true;
if (s1 == "thousand")
if (s2 == "hundred")
return true;
return false;
}
int splitAndCmput(string &s, stack<string> &nums, map<string, int> &num){
string ts;
int start = 0, end = 0;
while (end != string::npos){
end = s.find(' ', start);
nums.push(s.substr(start,end - start));
start = end + 1;
}
int ans = 0;
i