Simple calculator Java Implementation hdu1237

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.