1503140110-blue bridge cup-previous Questions and Replies

Source: Internet
Author: User

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 ;}


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.