Problem description Observation Number: 12321,123321 all have a common feature, which is the same whether reading from left to right or from right to left. Such numbers are called: palindrome numbers.
The subject asks you to find some 5-bit or 6-bit decimal digits. Meet the following requirements:
The sum of the individual digits of the number equals the integer entered. The input format is a positive integer n (10<n<100), which indicates the number of digits and that are required to be satisfied. The output formats several lines, each containing a 5-bit or 6-bit integer that satisfies the requirement.
Numbers are arranged in order from small to large.
If no conditions are 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 the palindrome sequence of the table hit well, calculated exactly 1800, so I array open 2000
Then sweep the front and back, and then the output will meet the conditions.
AC Code:
[CPP]View Plaincopyprint?
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
- Using namespace std;
- const INT MAXN = 2000;
- int PALIN[MAXN], num = 0;
- int Is_palin (int n) //Determine if it is a palindrome number
- {
- 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 () //palindrome number playing table
- {
- For (int i=10000; i<=999999; i++)
- {
- if (Is_palin (i)) palin[num++] = i;
- }
- }
- int fun (int n) //Determine if 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;
- }
Blue Bridge Mug-palindrome number (string!!) )