英文数字计算器的简化版本
任务
编写一个将字符串作为输入并输出表达式结果的程序。
规则
输入的字符串将是单词而不是数字。
不会有括号。
计算顺序将相除,相乘,相减然后相加。
对于相同的操作,必须从左到右进行计算。
所有输入数字都是-999至999(包括两端)的整数
输出将是任何范围的整数。
除法永远是完全可分割的,零永远不是分母。
输入的大小写限制是可选的。您不必检查输入的有效性。
数字格式
0 to 20 -> zero,one,two...nineteen,twenty
21 to 99 -> twenty one,twenty two.....ninety eight,ninety nine
100 to 999 -> one hundred, one hundred one, one hundred two...one hundred ten....two hundred fifty....nine hundred ninety eight,nine hundred ninety nine
对于负数:minus加到正数
操作格式
Addition: one plus two
Subtraction: one minus two
Multiplication: one time two #Note that for one on the left of multiplication, it is one time and not times.
two times one hundred
Division: forty divided by two
例子:
o/p <- input
20 four times five
35 twenty plus fifteen
70 fifty plus five times four
-90 minus one time ninety
25 twenty one minus minus four
45 ninety divided by two
700 one time seven hundred
555 one hundred eleven times two plus three hundred thirty three
99 one hundred plus minus one
45 forty five plus two hundred times zero
4 four
-3 three minus three minus three
这是代码高尔夫球,所以最短的代码胜出
1
重复?-我认为这已经足够接近了。
—
Kirill L.
确实非常接近。但是我认为这个规范更好,并且有更多合理的限制。
—
Arnauld
@Arnauld我会保持打开状态,但是如果其他人有不同的看法,只需将其标记为重复即可。
—
Vedant Kandoi
我说
—
Jo King
one times two。使用time正常吗?
我想你的意思是“一次小号七百”?
—
ouflak