| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10310 | Math Loop |
|
| 10368 | mid2補考_problem1 |
|
| 10369 | sosort |
|
Description
Observe the following instructions to solve a simple problem.
1. Input a sequence A, and then arrange the sequence number from large to small in order to get the new sequence B.
2. Do in the same way by step 1, but this time arrange the sequence A from small to large in order to get another sequence C.
3. Calculate the difference of B and C, that is, B-C.
4. Use B-C in step 3 as a new sequence A and repeat the above steps 1 to 3.
5. The repetitions end when a difference has been observed in the previous operations.
6. Finally you need to print the times that step 3 is executed.
Note: the input won’t be 0.
Example:
For the sequence A=3412, the sequence B from large to small is 4321. Besides, the sequence C from small to large is 1234.
Then follow the above instructions, we have 4321 - 1234 = 3087, 8730 - 378 = 8352, 8532 - 2358 = 6174, 7641 - 1467 = 6174.
In this case, you should print the number 4.
For another sequence A=12345, the sequence B from large to small is 54321. Besides, the sequence C from small to large is 12345.
Then follow the above instructions, we have 54321 - 12345 = 41976, 97641 - 14679 = 82962, 98622 - 22689 = 75933, 97533 - 33579 = 63954, 96543 - 34569 = 61974, 97641 - 14769 = 82962.
In this case, you should print the number 6.
Input
The input sequence contains no more than six digits.
Output
The times that step 3 is executed.
Note that there is a newline character at the end of the output.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
The input contains two polynomials f(x) and g(x).
f(x) = amxm + a(m-1)x(m-1) + ⋯ + a1x1 + a0x0
g(x) = bnxn + b(n-1)x(n-1) + ⋯ + b1x1 + b0x0
where m,n∈N, 0≤m,n≤10.
Compute h(x) = f(x)g(x).
Note that all the coefficients are integers.
Input
m
am a(m-1) … a1 a0
n
bn b(n-1) … b1 b0
Note that the coefficients are separated by a blank.
Output
The coefficients of h(x) in descending power order.
Use "%d " to print each coefficient and there is a newline at the end.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
The input contains three integers of the same length (same number of digits).
For example,
3412
5232
9128
For each integer, we rearrange its digits from small to large and produce a new integer. Therefore, the three integers above become
1234
2235
1289
The output shows the three integers in an increasing order, that is,
1234
1289
2235
You may use the following piece of code:
/* Using bubble sort to rearrange an array A[n] */
for (i = 0; i < n; i++) {
for (j = 1; j < n; j++) {
if (A[j-1] > A[j]) {
/* swap A[j-1] A[j] */
}
}
}
Input
The length of three integers, 1 ≤ length ≤ 9.
Three integers of the same length.
Output
Three rearranged integers in an increasing order.
Print a newline at the end of each integer.