Expression
题目
Description
Given a expression with only addition and multiplication, calculate the value.
Input
One line with the expression, with characters 0-9, ‘+’, and ‘*’. The number is 0~231-1
the number of ‘+’ character and ‘*’ character will <= 300
Output
One line, the value of the expression. If the length of the value is longer than 4, output the last 4. And do not output the leading zero.
Example Input
1+1*3+4
Example Output
8
Example Input
1+1234567890*1
Example Output
7891
Example Input
1+1000000003*1
Example Output
4
分析
题目就是一个计算器,只是我们输入的数字,全都模了10000而已。题目看起来很简单,但是还有两个需要注意的问题:
- 数字和运算符的抓取和存储
- 运算的优先级
大家可以先自己考虑一下,自己会怎么解决这两个问题。
代码

总结
我就是被召唤来的苦力。
本文介绍了一种简易计算器的设计思路,主要关注如何处理数学表达式中的加法和乘法操作。文章探讨了数字与运算符的抓取及存储方式,并讨论了如何处理运算的优先级问题。

被折叠的 条评论
为什么被折叠?



