题目大意是这样的,就是:
"one" => 1
"twenty" => 20
"two hundred forty-six" => 246
"seven hundred eighty-three thousand nine hundred and nineteen" => 783919
转换的范围是0到1000,000,注意转换需要支持'and'。
先声明这个不是作业帮哈,我自己完成了已经,也pass了,使用递归的思路做的,按thousand、hundred这种有特殊意义的词分段,之后再转换,不过总感觉不是最好的方法,应该还有更简单的方法吧
求大神给讲解讲解。
可以直接从左往右过词,
例如
seven hundred eighty-three thousand nine hundred and nineteen设置
num = 0读
seven,则把num设为7读
hundred,则把num乘以100,变成700读
eighty-three,则把num加上83变成783... 就是遇到读到数字就相加,读到单位就相乘,以此类推