ZJU2017 Simple Arithmetics-high-precision computing + format processing

Source: Internet
Author: User

Zju2017 pku1396 simple arithmetics-Central Europe 2000

Description:

Enter two numbers and an operator. The length of a number cannot exceed 500. The operator can be +,-, or. Results must be output in the "vertical calculation" format. (The format requirement is not described)

Analysis:

High-Precision Computing should not be a problem for those who can stick to this topic. The trouble with this question is to followVertical formatOutput, and some details in the question area are not completely described. Today I almost died here ......

I hope that my friend from Wa will not be able to find out where he was wrong. This problem report should be helpful to you ~ :) So I intentionally wrote the question numbers zju and PKU at the top ~

Tragic debugging process:After wa several times, we did a lot of random data for testing and another Helper Program for testing. Print the output results to the file, and then observe with the naked eye to find several fatal errors. My Helper Program verifies that my computing results are correct, the reason for WA must be the format ...... Then I read the questions several times again, and repeat returned the question "doing random data Debugging "...... ◎ # ¥ ※......

The following are considerations, Mainly discussing format processing:

1. The input number must be a positive number. If the operator is "-", the second number must be smaller than the first number.

2. The length of the constant line must be properly handled. The principle is that the horizontal line must be right aligned; its leftmost end is the leftmost end of the upper and lower numbers. Example:
200
* 200
----
0
0
400
-----
40000
9
* 121
----
9
18
9
----
1089
999
+ 11
----
1010

3. If alignment is satisfied, the output should contain as few leading spaces as possible.

4. Do not output leading 0. When a number is 0, do not output anything.

5. Most importantly, when multiplication has only one intermediate result, do not output the intermediate result. The following is the correct output:
189
* 9
----
1701

Either of the following is incorrect:
189
* 9
----
1701
----
1701
189
* 9
----
----
1701

6. Do not output spaces after the intermediate result of multiplication.

7. Add an empty row after each group of output data.

These considerations are only applicable to format processing when you can ensure that your high-precision computing results are good. If you cannot find your own errors during debugging for half a day, give you some suggestions.

First, make sure that you have no problem with high-precision computing. You can write a small program to randomly generate data in the int range and output the computing results to the file in the correct format. Then write a small program to verify the results. If this step is okay, output the results of random data to the file in the required format, and then observe with the naked eye ......

The code is long and ugly, so it won't be posted ......

This type of question depends on its own basic knowledge, and the code has little reference value.

 

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.