Simple CalculatorTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 15190 Accepted Submission (s): 5184
Problem description reads a non-negative integer that contains only +,-, *,/, evaluates the expression, and computes the value of the formula.
The input test inputs contain several test cases, one row for each test case, and no more than 200 characters per line, separated by a space between integers and operators. There is no illegal expression. When only 0 o'clock input is completed in a row, the corresponding result is not output.
Output outputs 1 rows for each test case, that is, the value of the expression, exactly 2 digits after the decimal point.
Sample Input
1 + 24 + 2 * 5-7/110
Problem-solving ideas: The use of LinkedList to achieve the queue team to achieve a simple operation, the use of two analog queue s1,s2,s1 used to load the value, S2 used to install operators, before the team, we put multiplication sign and division sign before and after the two values are calculated and queued, and then other non-processing queued. Finally, the numbers and operators are taken from the first team to perform the corresponding operations. (PS: I began to be affected by the class, with the stack to do, the idea is the idea, but WA, the results found that subtraction, you need to be the previous one minus, and the addition of the operation, if it is used in the stack, it will take the value of the front of the addition, and will not take the front of the symbol directly to So later instead of the queue to do, the pit of a face of blood, but the topic is very water, very water, very water, important things to say three times)
Code:
Sample Output
3.0013.36
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Simple calculator Java Implementation hdu1237