Blue Bridge cup, official website of Blue Bridge cup
Time limit of the number of input files: 1.0 s memory limit: 256.0 MB Problem 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
Idea: first, we need to lay the table of the Back-to-text sequence and calculate the result as 1800, so the 2000 I opened in the array
Then, you can scan it from the beginning to the end to output the output if the conditions are met ..
AC code:
# Include <cstdio> # include <cstring> # include <algorithm> using namespace std; const int maxn = 2000; int palin [maxn], num = 0; int is_palin (int n) // determines whether it is the number of input files {if (n <100000) {if (n/10000 = n % 10) & (n/1000% 10 = n/10% 10) return 1;} else {if (n/100000 = n % 10) & (n/10000% 10 = n/10% 10) & (n/1000% 10 = n/100% 10) return 1;} return 0 ;} void init () // enter the number of input files in the table {for (int I = 10000; I <= 999999; I ++) {if (is_palin (I) pali N [num ++] = I ;}} int fun (int n) // determine whether the condition is met {int t = 0, m = n; while (m) {t + = m % 10; m/= 10;} return t;} int main () {init (); int n; while (scanf ("% d ", & n )! = EOF) {if (n <5 | n> 54) {printf ("-1 \ n"); continue ;}for (int I = 0; I <num; I ++) {if (fun (palin [I]) = n) printf ("% d \ n", palin [I]) ;}} return 0 ;}