解题思路:
遍历所有可能的情况




注意事项:
最高为不能为0,无结果时返回-1




参考代码:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(int argc, char *argv[])
{
    char a[11]= {"0123456789"};
    char b[6]= {"00000"},c[7]= {"000000"};
    int i1,i2,i3,i4,i5,i6,j,flag,s,num,sum,counts=0;
    scanf("%d",&num);
    for(i1=1; i1<10; i1++)
    {
        b[0]=a[i1];
        for(i2=0; i2<10; i2++)
        {
            b[1]=a[i2];
            for(i3=0; i3<10; i3++)
            {
                b[2]=a[i3];
                for(i4=0; i4<10; i4++)
                {
                    b[3]=a[i4];
                    for(i5=0; i5<10; i5++)
                    {
                        b[4]=a[i5];
                        sum=0;
                        for(s=0; s<5; s++)
                        {
                            sum=sum+(b[s]-'0');
                        }
                        if(sum==num)
                        {
                            flag=1;
                            for(j=0; j<2; j++)
                            {
                                if(b[j]==b[4-j])continue;
                                else flag=0;

                            }
                            if(flag)
                                {puts(b);counts++;}
                        }
                    }
                }
            }
        }
    }
    /*--------------------------------------------------*/
    for(i1=1; i1<10; i1++)
    {
        c[0]=a[i1];
        for(i2=0; i2<10; i2++)
        {
            c[1]=a[i2];
            for(i3=0; i3<10; i3++)
            {
                c[2]=a[i3];
                for(i4=0; i4<10; i4++)
                {
                    c[3]=a[i4];
                    for(i5=0; i5<10; i5++)
                    {
                        c[4]=a[i5];
                        for(i6=0; i6<10; i6++)
                        {
                            c[5]=a[i6];
                            sum=0;
                            for(s=0; s<6; s++)
                            {
                                sum=sum+(c[s]-'0');
                            }
                            if(sum==num)
                            {
                                flag=1;
                                for(j=0; j<3; j++)
                                {
                                    if(c[j]==c[5-j])continue;
                                    else flag=0;

                                }
                                if(flag)
                                    {puts(c);counts++;}
                            }
                        }
                    }
                }
            }
        }
    }
if(!counts)printf("%d",-1);
    return 0;
}


点赞(2)
 

0.0分

0 人评分

C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:

一点编程也不会写的:零基础C语言学练课程

解决困扰你多年的C语言疑难杂症特性的C语言进阶课程

从零到写出一个爬虫的Python编程课程

只会语法写不出代码?手把手带你写100个编程真题的编程百练课程

信息学奥赛或C++选手的 必学C++课程

蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程

手把手讲解近五年真题的蓝桥杯辅导课程

评论列表 共有 0 条评论

暂无评论