Reprint please indicate the source: http://blog.csdn.net/u010734277
In Peking University open JUDGE (seemingly with POJ the same system) to do the question, found a problem, some problems first submitted is presentation error, will format wrong place corrected later, became runtime error.
Topic is
We often encounter the addition of two polynomial, where we need to use a program to simulate
The implementation adds two polynomials together. First, we will have two polynomials, each polynomial is
A separate row in which each polynomial is represented by multiple integer pairs, such as coefficients and power numbers.
such as polynomial 2x20-x17+ 5x9-7x7+ 16x5+ 10x4+ 22x2-15
The corresponding expression is: 2 20-1 17 5 9-7 7 16 5 10 4 22 2-15-0.
in order to mark the end of each line polynomial, in an expression
followed by an integer pair with a power number negative.
At the same time, the order of the power number of the input expression is random.
All we need to do is add up the two polynomials we've given.
Input input includes multiple lines.
The first line of integer n, which indicates how many sets of polynomials need to be summed. (1 is a 2n line integer and each row is an expression of a polynomial.) Represents the polynomial that an n group needs to add.
The length of each line is less than 100. The output output consists of n rows, and the results of the addition of 1 sets of polynomials per behavior.
In the output of each row, each item of the polynomial is represented by a string in the form of "[X y]", X is the factor of the item, and Y is the power of the item. It is required to rank the power from highest to lowest in each term, that is, to first output the term of a power number, and then output a lower power.
Items with zero coefficients are not exported. Sample input
2
-1 2 5 9-7 7 4 2-15 0 5 0-1 2 7 7 3 4
2-7 4 8-8 5 0 1 17 2 23
8-4 7-18 0 1 5 4 0-1 12 7-7 5 3 17 23 4 15 10-10 5 13 5 2 19 9-7
Sample output
[2 20] [2 19] [2 17] [15 10] [5 9] [6 5] [14 4] [35 2] [ -22 0]
[2 23] [2 19] [2 17] [15 10] [6 8] [8 7] [-3 5] [44 4] [22 2] [-18 0]
The first time to do, want to steal the lazy, thinking is very simple, with a B-array record from 1 to 100 times of the case, such as b[1]=10 on behalf of the 1 square front of the coefficient of 10. So in the output, starting from 100 to 1 to retrieve, encountered is not zero on the output. The first time to submit because there is no space between each group of data, is presentation error, but with the space, it becomes runtime error.
Normal feeling words, encountered presentation error on behalf of the code is no problem, but the format of the problem. But this time it's more special.
The problem with this program is that if the power of the number is greater than the number of arrays, it cannot be run.
OJ judgment, is the test data in each group to test, encountered presentation error, it will not continue to test down. Perhaps the first group of test data is relatively small, no more than 100 of the range, so the decision for the format error, the format will be corrected, you will continue to test downward, at this time, there is runtime error. Therefore, when the OJ above, see presentation error, may not be just the output format error, probably because the first data format is wrong, and then the data is not tested at all.