1503140110-blue bridge cup-previous Questions and Replies
Time limit for returning texts to previous questions: 1.0 s memory limit: 256.0 MBProblem description observation number: 12321,123321 has a common feature, which is the same whether it is left-to-right or right-to-left. This number is called a return number.
This question requires you to find some 5-or 6-digit decimal numbers. The following requirements are met:
The sum of digits of the number is equal to the input integer. The input format is a positive integer n (10 <n <100), indicating the number and that meet the requirements. The output format is several rows. Each row contains a five-or six-digit integer that meets the requirements.
Numbers are arranged in ascending order.
If the condition is not met, output:-1 sample input 44 sample output 99899
499994
589985
598895
679976
688886
697796
769967
778877
787787
796697
859958
868868
877778
886688
895598
949949
958859
967769
976679
985589
994499 sample input 60 sample output-1 solution idea because it is symmetric between the left and right, it is good to judge half. Code
# Include <stdio. h ># include <algorithm> using namespace std; int num [100000]; int main () {int n; int I, j, k, l, m; int sum, now; while (scanf ("% d", & n )! = EOF) {sum = 0; for (I = 1; I <10; I ++) {k = 0; // now = I * 2; if (I * 2 <= n) {for (j = 0; j <10; j ++) {// now + = j * 2; if (I + j) * 2 <= n) {if (n-(I + j) * 2> = 0 & n-(I + j) * 2 <= 9) {m = I * 10000 + j * 1000 + (n-(I + j) * 2) * 100 + j * 10 + I; num [sum ++] = m ;}for (l = 0; l <10; l ++) {// now + = l * 2; if (I + j + l) * 2 = n) {m = I * 100000 + j * 10000 + l * 1000 + l * 100 + j * 10 + I; num [sum ++] = m ;}}}}// originally defined now to determine whether it is equal to n, but observe my program, it can be found that // If an operation is not included in num, but the value of now has been added, and it will affect the next comparison of sort (num, num + sum ); if (sum = 0) printf ("-1 \ n"); else {for (I = 0; I <sum; I ++) printf ("% d \ n", num [I]) ;}} return 0 ;}