有一个14位数。由 2个1 2个2 2个3 2个4 2个5 2个6 2个7组成!其中,两个1中有一个数字,2个2中有2个数字……2个7中有7个数字入:73625324765141

// 2016/2/21 10:32 准备再次解答这个问题了。小学的时候使用人工枚举方法,这个我不擅长!现在决定用程序来解决了!
// 2016/2/21 23:31 初步解决了!!!!


// 给你一个高难度的题目。
// 有一个14位数。
// 由 2个1 2个2 2个3 2个4 2个5 2个6 2个7组成
// 其中。两个1中有一个数字。
// 2个2中有2个数字
// 2个3中有3个数字
// 2个4中有4个数字
// 2个5中有5个数字。
// 2个6中有6个数字。
// 2个7中有7个数字
// 
// 请给出一个 这样的14位数字(总数大于10个。给一个即可!)
// 这是我小学6年级的时候的 奥数考题!






#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>


int main(void)
{
unsigned char ucArray[15] = {0};
// int i = 0;

// for(i=1; i<15; i++)
// {
// printf("*ucArray[%d]=%d\n", i, ucArray[i]);
// }


// 2016/2/21 11:10 第一位数字完成
int bit01 = 0;
for(bit01=1; bit01<=7; bit01++)
{
unsigned char ucArray01[15] = {0};
int temp01 = 0;
for(temp01=0; temp01<15; temp01++)
{
ucArray01[temp01] = ucArray[temp01];
}

ucArray01[1] = bit01;
ucArray01[1+bit01+1] = bit01;

// for(temp01=1; temp01<15; temp01++)
// {
// printf("%d=%d ", temp01, ucArray01[temp01]);
// }
// 
// printf("*\n");




// 2016/2/21 11:33 第二位数字完成
int bit02 = 0;
for(bit02=1; bit02<=7; bit02++)
{
unsigned char ucArray02[15] = {0};
int temp02 = 0;
for(temp02=0; temp02<15; temp02++)
{
ucArray02[temp02] = ucArray01[temp02];
}

// 2016/2/21 21:12 第2位数字不能喝第1位数字重复
// if(bit02==bit01)
// {
// continue;
// }

for(temp02=1; temp02<15; temp02++)
{
if(ucArray02[temp02]>0)
{
// continue;

if(ucArray02[temp02]==bit02)
{
temp02 = 99;
break;
}


}
}

if(temp02>15)
{
continue;
}

// 2016/2/21 11:17 需要判断第2位数字 和 接着的数字必须没有被占用。还有就是不能重复
if(0==ucArray02[2])
{
ucArray02[2] = bit02;
}
else
{
// continue;
goto goto02;
}

if(0==ucArray02[2+bit02+1])
{
ucArray02[2+bit02+1] = bit02;
}
else
{
continue;
}

goto02: ;
// for(temp02=1; temp02<15; temp02++)
// {
// printf("%d=%d ", temp02, ucArray02[temp02]);
// }
// 
// printf("*\n");





// 2016/2/21 20:18 第三位数字完工
int bit03 = 0;
for(bit03=1; bit03<=7; bit03++)
{
unsigned char ucArray03[15] = {0};
int temp03 = 0;
for(temp03=0; temp03<15; temp03++)
{
ucArray03[temp03] = ucArray02[temp03];
}

for(temp03=0; temp03<15; temp03++)
{
if(ucArray03[temp03]>0)
{
if(ucArray03[temp03]==bit03)
{
// continue;
temp03 = 99;
break;
}
}
}

if(temp03>15)
{
continue;
}

// 2016/2/21 11:17 需要判断第2位数字 和 接着的数字必须没有被占用。还有就是不能重复
if(0==ucArray03[3])
{
ucArray03[3] = bit03;
}
else
{
// continue;
goto goto03;
}

if(0==ucArray03[3+bit03+1])
{
ucArray03[3+bit03+1] = bit03;
}
else
{
continue;
}

goto03: ;
// for(temp03=1; temp03<15; temp03++)
// {
// printf("%d=%d ", temp03, ucArray03[temp03]);
// }
// 
// printf("*\n");




// 2016/2/21 20:18 第四位数字(将所有的03替换为04,还有就是02替换为03)
int bit04 = 0;
for(bit04=1; bit04<=7; bit04++)
{
unsigned char ucArray04[15] = {0};
int temp04 = 0;
for(temp04=0; temp04<15; temp04++)
{
ucArray04[temp04] = ucArray03[temp04];
}

for(temp04=1; temp04<15; temp04++)
{
if(ucArray04[temp04]>0)
{
if(ucArray04[temp04]==bit04)
{
// continue;
temp04 = 99;
break;
}
}
}

if(temp04>15)
{
continue;
}

// 2016/2/21 11:17 需要判断第2位数字 和 接着的数字必须没有被占用。还有就是不能重复
if(0==ucArray04[4])
{
ucArray04[4] = bit04;
}
else
{
// continue;
goto goto04;
}

if(0==ucArray04[4+bit04+1])
{
ucArray04[4+bit04+1] = bit04;
}
else
{
continue;
}

goto04: ;
// for(temp04=1; temp04<15; temp04++)
// {
// printf("%d=%d ", temp04, ucArray04[temp04]);
// }
// 
// printf("*\n");




// 2016/2/21 20:30 第5位数字
int bit05 = 0;
for(bit05=1; bit05<=7; bit05++)
{
unsigned char ucArray05[15] = {0};
int temp05 = 0;
for(temp05=0; temp05<15; temp05++)
{
ucArray05[temp05] = ucArray04[temp05];
}

for(temp05=1; temp05<15; temp05++)
{
if(ucArray05[temp05]>0)
{
if(ucArray05[temp05]==bit05)
{
// continue;
temp05 = 99;
break;
}
}
}

if(temp05>15)
{
continue;
}

// 2016/2/21 11:17 需要判断第2位数字 和 接着的数字必须没有被占用。还有就是不能重复
if(0==ucArray05[5])
{
ucArray05[5] = bit05;
}
else
{
// continue;
goto goto05;
}

if(0==ucArray05[5+bit05+1])
{
ucArray05[5+bit05+1] = bit05;
}
else
{
continue;
}

goto05: ;
// for(temp05=1; temp05<15; temp05++)
// {
// printf("%d=%d ", temp05, ucArray05[temp05]);
// }
// 
// printf("*\n");




// 2016/2/21 20:38 第6位数字
int bit06 = 0;
for(bit06=1; bit06<=7; bit06++)
{
unsigned char ucArray06[15] = {0};
int temp06 = 0;

for(temp06=0; temp06<15; temp06++)
{
ucArray06[temp06] = ucArray05[temp06];
}

for(temp06=1; temp06<15; temp06++)
{
if(ucArray06[temp06]>0)
{
if(ucArray06[temp06]==bit06)
{
temp06 = 99;

break;
}
}
}

if(temp06>15)
{
continue;
}

if(0==ucArray06[6])
{
ucArray06[6] = bit06;
}
else
{
goto goto06;
}

if(0==ucArray06[6+bit06+1])
{
ucArray06[6+bit06+1] = bit06;
}
else
{
continue;
}

goto06: ;
// for(temp06=1; temp06<15; temp06++)
// {
// printf("%d=%d ", temp06, ucArray06[temp06]);
// }
// 
// printf("*\n");




// 2016/2/21 21:52 第7位数字
int bit07 = 0;
for(bit07=1; bit07<=7; bit07++)
{
unsigned char ucArray07[15] = {0};
int temp07 = 0;

for(temp07=0; temp07<15; temp07++)
{
ucArray07[temp07] = ucArray06[temp07];
}

for(temp07=1; temp07<15; temp07++)
{
if(ucArray07[temp07]>0)
{
if(ucArray07[temp07]==bit07)
{
temp07 = 99;

break;
}
}
}

if(temp07>15)
{
continue;
}

if(0==ucArray07[7])
{
ucArray07[7] = bit07;
}
else
{
goto goto07;
}

if((7+bit07+1)>14)
{
continue;
}

if(0==ucArray07[7+bit07+1])
{
ucArray07[7+bit07+1] = bit07;
}
else
{
continue;
}

goto07: ;
// for(temp07=1; temp07<15; temp07++)
// {
// printf("%d=%d ", temp07, ucArray07[temp07]);
// }
// 
// printf("*\n");




// 2016/2/21 21:58 第8个数字
       int bit08 = 0;
       for(bit08=1; bit08<=7; bit08++)
       {
        unsigned char ucArray08[15] = {0};
        int temp08 = 0;
       
        for(temp08=0; temp08<15; temp08++)
        {
        ucArray08[temp08] = ucArray07[temp08];
        }
       
        for(temp08=1; temp08<15; temp08++)
        {
        if(ucArray08[temp08]>0)
        {
        if(ucArray08[temp08]==bit08)
        {
        temp08 = 99;
       
        break;
        }
        }
        }
       
        if(temp08>15)
        {
        continue;
        }
       
        if(0==ucArray08[8])
        {
        ucArray08[8] = bit08;
        }
        else
        {
        goto goto08;
        }
       
        if((8+bit08+1)>14)
        {
        continue;
        }
       
        if(0==ucArray08[8+bit08+1])
        {
        ucArray08[8+bit08+1] = bit08;
        }
        else
        {
        continue;
        }
       
goto08:         ;
        // for(temp08=1; temp08<15; temp08++)
        // {
        // printf("%d=%d ", temp08, ucArray08[temp08]);
        // }
        // 
        // printf("*\n");
       
       
       
       
        // 2016/2/21 22:03 第9位数字
               int bit09 = 0;
               for(bit09=1; bit09<=7; bit09++)
               {
                unsigned char ucArray09[15] = {0};
                int temp09 = 0;
               
                for(temp09=0; temp09<15; temp09++)
                {
                ucArray09[temp09] = ucArray08[temp09];
                }
               
                for(temp09=1; temp09<15; temp09++)
                {
                if(ucArray09[temp09]>0)
                {
                if(ucArray09[temp09]==bit09)
                {
                temp09 = 99;
               
                break;
                }
                }
                }
               
                if(temp09>15)
                {
                continue;
                }
               
                if(0==ucArray09[9])
                {
                ucArray09[9] = bit09;
                }
                else
                {
                goto goto09;
                }
               
                if((9+bit09+1)>14)
                {
                continue;
                }
               
                if(0==ucArray09[9+bit09+1])
                {
                ucArray09[9+bit09+1] = bit09;
                }
                else
                {
                continue;
                }
               
goto09:                 ;
                // for(temp09=1; temp09<15; temp09++)
                // {
                // printf("%d=%d ", temp09, ucArray09[temp09]);
                // }
                // 
                // printf("*\n");
               
               
               
               
                // 2016/2/21 22:08 第10位数字
                       int bit10 = 0;
                       for(bit10=1; bit10<=7; bit10++)
                       {
                        unsigned char ucArray10[15] = {0};
                        int temp10 = 0;
                       
                        for(temp10=0; temp10<15; temp10++)
                        {
                        ucArray10[temp10] = ucArray09[temp10];
                        }
                       
                        for(temp10=1; temp10<15; temp10++)
                        {
                        if(ucArray10[temp10]>0)
                        {
                        if(ucArray10[temp10]==bit10)
                        {
                        temp10 = 99;
                       
                        break;
                        }
                        }
                        }
                       
                        if(temp10>15)
                        {
                        continue;
                        }
                       
                        if(0==ucArray10[10])
                        {
                        ucArray10[10] = bit10;
                        }
                        else
                        {
                        goto goto10;
                        }
                       
                        if((10+bit10+1)>14)
                        {
                        continue;
                        }
                       
                        if(0==ucArray10[10+bit10+1])
                        {
                        ucArray10[10+bit10+1] = bit10;
                        }
                        else
                        {
                        continue;
                        }
                       
goto10:                         ;
                        // for(temp10=1; temp10<15; temp10++)
                        // {
                        // printf("%d=%d ", temp10, ucArray10[temp10]);
                        // }
                        // 
                        // printf("*\n");
                       
                       
                       


// 1=7 2=4 3=1 4=3 5=1 6=5 7=4 8=3 9=7 10=2 11=0 12=5 13=2 14=0 *
// 1=7 2=4 3=1 4=3 5=1 6=5 7=4 8=3 9=7 10=0 11=2 12=5 13=0 14=2 *
// 2016/2/21 22:21 大量出错 初步判断为数组越界了!!!!                        
                        // 2016/2/21 22:15 第11位数字
                               int bit11 = 0;
                               for(bit11=1; bit11<=7; bit11++)
                               {
                                unsigned char ucArray11[15] = {0};
                                int temp11 = 0;
                               
                                for(temp11=0; temp11<15; temp11++)
                                {
                                ucArray11[temp11] = ucArray10[temp11];
                                }
                               
                                for(temp11=1; temp11<15; temp11++)
                                {
                                if(ucArray11[temp11]>0)
                                {
                                if(ucArray11[temp11]==bit11)
                                {
                                temp11 = 99;
                               
                                break;
                                }
                                }
                                }
                               
                                if(temp11>15)
                                {
                                continue;
                                }
                               
                                if(0==ucArray11[11])
                                {
                                ucArray11[11] = bit11;
                                }
                                else
                                {
                                goto goto11;
                                }
                               
                                if((11+bit11+1)>14)
                                {
                                continue;
                                }
                               
                                if(0==ucArray11[11+bit11+1])
                                {
                                ucArray11[11+bit11+1] = bit11;
                                }
                                else
                                {
                                continue;
                                }
                               
goto11:                                 ;
                                for(temp11=1; temp11<12; temp11++)
                                {
                                if(0==ucArray11[temp11])
                                {
                                temp11 = 88;
                                break;
                                }
                                }
                               
                                if(temp11>15)
                                {
                                continue;
                                }
                               
                                // for(temp11=1; temp11<15; temp11++)
                                // {
                                // printf("%d=%d ", temp11, ucArray11[temp11]);
                                // }
                                // 
                                // printf("*\n");
                               
                               
                               
                               
                                // 2016/2/21 22:44 第12位数字
                                       int bit12 = 0;
                                       for(bit12=1; bit12<=7; bit12++)
                                       {
                                        unsigned char ucArray12[15] = {0};
                                        int temp12 = 0;
                                       
                                        for(temp12=0; temp12<15; temp12++)
                                        {
                                        ucArray12[temp12] = ucArray11[temp12];
                                        }
                                       
                                        for(temp12=1; temp12<15; temp12++)
                                        {
                                        if(ucArray12[temp12]>0)
                                        {
                                        if(ucArray12[temp12]==bit12)
                                        {
                                        temp12 = 99;
                                       
                                        break;
                                        }
                                        }
                                        }
                                       
                                        if(temp12>15)
                                        {
                                        continue;
                                        }
                                       
                                        if(0==ucArray12[12])
                                        {
                                        ucArray12[12] = bit12;
                                        }
                                        else
                                        {
                                        goto goto12;
                                        }
                                       
                                        if((12+bit12+1)>14)
                                        {
                                        continue;
                                        }
                                       
                                        if(0==ucArray12[12+bit12+1])
                                        {
                                        ucArray12[12+bit12+1] = bit12;
                                        }
                                        else
                                        {
                                        continue;
                                        }
                                       
goto12:                                         ;
                                        // for(temp12=1; temp12<13; temp12++)
                                        for(temp12=1; temp12<15; temp12++)
                                        {
                                        if(0==ucArray12[temp12])
                                        {
                                        temp12 = 88;
                                        break;
                                        }
                                        }
                                       
                                        if(temp12>15)
                                        {
                                        continue;
                                        }
                                       
                                        for(temp12=1; temp12<15; temp12++)
                                        {
                                        // printf("%d=%d ", temp12, ucArray12[temp12]);
                                        printf("%d", ucArray12[temp12]);
                                        }
                                       
                                        printf("*\n");
                                       }
                               }
                       }
               }
       }
}
}
}
}
}
}



}

return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值