Blue Bridge Cup: palindrome number

Source: Internet
Author: User

<title>Blue Bridge Cup: palindrome number</title> Blue Bridge Cup: palindrome number

Problem description
Observation numbers: 12321,123321 have a common feature that 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.
Input format
A positive integer n (10<n<100) that represents the number of digits and that are required to be satisfied.
Output format
Several rows, 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

// createtime:2014-12-17 19:21:30#include <cstdio>int Match5(int Num) {if(num = = 0) {return0; }Else if(num = = 2) {printf ("10001\n");return1; }Else if(num = = 3) {printf ("10101\n");return1; }int sum= 0;if(num% 2 = = 0) { for(int J= 1; J < 10; J + +) {// number of first digits             for(int k= 0; K < 10; k++) { for(int I= 0; I < 10; i + = 2) {// must be an even number in the middle                    if(i + 2 * (j+k) = = num) {printf ("%d%d%d%d%d\n", J, K, I, K, j);                    sum++; }                }            }        }    }Else if(num% 2! = 0) { for(int J= 1; J < 10; J + +) { for(int k= 0; K < 10; k++) { for(int I= 1; I < 10; i + = 2) {// the middle must be an odd number                    if(i + 2 * (j+k) = = num) {printf ("%d%d%d%d%d\n", J, K, I, K, j);                    sum++; }                }            }        }    }returnsum;}int Match6(int Num) {if(num = = 0 | | num% 2 = 0) {return0; }Else if(num = = 2) {printf ("100001\n");return1; num = NUM/2;int sum= 0; for(int I= 1; I <= 9; i++) {// number of first digits         for(int J= 0; J <= 9; J + +) { for(int k= 0; K <= 9; k++) {if(i + j + k = = num) {printf ("%d%d%d%d%d%d\n", I, J, K, K, J, I);                sum++; }            }        }    }returnsum;}int Main(void) {int N; scanf"%d", &n);if(MATCH5 (n) + MATCH6 (n) = = 0) {printf (" -1\n"); }return0;}

Blue Bridge Cup: palindrome number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.