題目要求html
輸入四則運算的規則和表達式,測試程序能夠自動判斷表達式是否符合規則java
輸入輸出示例:git
輸入:github
{ "config": { "numberOfExpression": 30, "range": 30, "hasFraction": false, "hasMultipleAndDivide": true, "hasParentheses": true }, "expressions": { "3 × ( 3 + 3 )": "18", "( 3 + 3 )": "6" } }
輸入參數說明:
在config中:spring
在expressions中express
輸出:apache
{ "config": { "numberOfExpression": 30, "range": 30, "hasFraction": false, "hasMultipleAndDivide": true, "hasParentheses": true, "hasNegative": false, "answer": false, "maxNumberOfOperation": 3 }, "results": [ { "3 × ( 3 + 3 )": { "true": "符合要求的表達式" } }, { "( 3 - 1 )": { "false": "題目中的乘除法不符合要求" } } ], "enough": false }
輸出參數說明:json
RESTful接口地址(試用版),api
運行地址數組
String generate(String configs)
入參,字符串類型,可配置項見配置參數:
{ "numberOfExpression": "10", "range": "10", "hasFraction": "false", "hasMultipleAndDivide": "true", "hasParentheses": "false", "hasNegative": "true", "answer": "true" }
返回:
[8 - 5 ÷ 6 × 9 = 0.5, 7 + 8 = 15.0, 9 × 9 = 81.0, 7 × 6 + 4 ÷ 7 = 42.57142857142857, 5 ÷ 7 - 4 = -3.2857142857142856, 2 - 9 - 1 + 1 = -7.0, 3 ÷ 2 × 6 = 9.0, 1 × 0 = 0.0, 4 × 3 = 12.0, 3 - 7 - 5 = -9.0]
String answer(String expression)
入參:
4 × ( 9'1/7 - 5 ) ÷ 3
返回:
4 × ( 9'1/7 - 5 ) ÷ 3 = 5.523809523809524
String retrieveDefaultTemplate()
返回默認的JSON配置:
{ "numberOfExpression": "10", "range": "10", "hasFraction": "false", "hasMultipleAndDivide": "true", "hasParentheses": "false", "hasNegative": "true", "answer": "true" }
注: 解析命令行參數採用了JCommander進行解析。
最初想法,實際上是很簡單粗暴的,把要生成的運算式當作字符串,這個字符串中: