当前位置:网站首页>Special palindromes of daily practice of Blue Bridge Cup

Special palindromes of daily practice of Blue Bridge Cup

2022-07-06 12:37:00 Jing Yu

The 13th Blue Bridge Cup individual competition and provincial competition will be held in 2022 year 4 month 9 Japan ( Saturday ) host , Take advantage of the time of winter vacation to hurry up and prepare for war . Because the blogger himself signed up for C/C++ Group , So all the updates are C/C++ Related knowledge . All the questions are the real questions of the question bank on the official website of the Blue Bridge Cup . Today is the fifth day of preparing for the battle .

subject :

123321 It's a very special number , It's the same thing to read from the left as it is to read from the right .
Enter a positive integer n, Programming for all such five and six decimal numbers , The sum of your numbers equals n .

Input format :

The input line , Contains a positive integer n.

Output format :

Output the integers satisfying the conditions in the order of small to large , Each integer takes up one line .

The sample input :

52

Sample output :

899998 
989989
998899

Data size and engagement

1<=n<=54.

Their thinking :

The number of palindromes was updated the day before , This is a special palindrome number , The solution is the same . Enter an integer first n, The sum of each digit is exactly equal to n, The title requires five and six digit output ( The first time I didn't see the title clearly, I only output five digits , Cause the test to only 20 branch ). When programming according to the requirements of the topic , You need to judge whether it is five digits or six digits in the cycle , Number of cycles i/100000 If it is equal to 0 It's five digits , Then it is to separate each one , All separated bits are added together with the input n equal , Just output this number . The output is complete after continuous loop judgment .

Complete code :

#include <stdio.h>
int main ()
{
	int a,b,c,d,e,f;
	int n;
	scanf("%d",&n);
	int i;
	for(i=10000;i<999999;i++)
	{
		if(i/100000==0)
		{
			a=i%10;
		    b=((i-a)/10)%10;
			c=((((i-a)/10)-b)/10)%10;
			d=((((((i-a)/10)-b)/10)-c)/10)%10;
			e=((((((((i-a)/10)-b)/10)-c)/10)-d)/10)%10;
			int sum= a*10000+b*1000+c*100+d*10+e*1;
			if(sum==i && a+b+c+d+e==n)
			{
		  		printf("%d\n",sum);
		  		
    		}
		}
		else
		{
			a=i%10;
			b=((i-a)/10)%10;
			c=((((i-a)/10)-b)/10)%10;
			d=((((((i-a)/10)-b)/10)-c)/10)%10;
			e=((((((((i-a)/10)-b)/10)-c)/10)-d)/10)%10;
			f=((((((((((i-a)/10)-b)/10)-c)/10)-d)/10)-e)/10)%10;
			int sum= a*100000+b*10000+c*1000+d*100+e*10+f;
			if(sum==i && a+b+c+d+e+f==n)
			{
		 		 printf("%d\n",sum);
    		}
		}
	}   
		
	return 0;
}

原网站

版权声明
本文为[Jing Yu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131522424604.html