Lanqiao Cup Test Questions Basic Practice Special Palindrome Number (Enumerated) (C language)

Problem Description

  123321 is a very special number. Reading it from the left is the same as reading it from the right.
  Enter a positive integer n, and program to find all such five-digit and six-digit decimal numbers, satisfying that the sum of the digits is equal to n.

Input format

  Enter a line containing a positive integer n.

Output format

  Output the integers that meet the conditions in ascending order, and each integer occupies one line.

Sample input

52

Sample output

899998
989989
998899

Data size and convention

  1<=n<=54。

 

#include<bits/stdc++.h>
int main()
{
	int n,i,j,k;
	scanf("%d",&n);
	for(i=1;i<10;i++)//五位数的 
	{
		for(j=0;j<10;j++)
		{
			for(k=0;k<10;k++)
			{
				if(i+i+j+j+k==n)
				{
					printf("%d%d%d%d%d",i,j,k,j,i);
					printf("\n");
				}
			}
		}
	}
	for(i=1;i<10;i++)//六位数的 
	{
		for(j=0;j<10;j++)
		{
			for(k=0;k<10;k++)
			{
				if(2*i+2*j+2*k==n)
				{
					printf("%d%d%d%d%d%d",i,j,k,k,j,i);
					printf("\n");
				
				}
				
			}
		}
	}
	return 0;
	 
}

A simple enumeration is OK

Guess you like

Origin blog.csdn.net/with_wine/article/details/114975151