文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>做个乘法题玩玩

做个乘法题玩玩

时间:2010-04-28  来源:chhaya

将0,1,2,3,4,5,6,7,8,9共10个数字填入下面的乘法公式中, 代替*号, 每个数字只能用2次,总共20个*刚刚好。  
      *** (被乘数)       *** (乘数)   ------       ***     ***   ***
--------   ***** (积)

#include <stdio.h>
#include <string.h>
#include <time.h>

int main()
{
    int a, b, c, d, ok;
    int i, j, k, out=1;
    int cnt[10];
    
    clock_t s, t;
    s = clock();

    for(i=100; i<=299 && out; i++)
    {
        for(j=112; j<=998 && out; j++)
        {
            if(j%100/10 == 0 || j % 10 == 0 || i % 10 == 0)
                 continue;
            memset(cnt, 0, sizeof(cnt));
            cnt[i/100]++;
            cnt[i%100/10]++;
            cnt[i%10]++;

            cnt[j/100]++;
            cnt[j%100/10]++;
            cnt[j%10]++;

            a = j % 10 * i;
            if(a > 999)
                continue;
            cnt[a/100]++;
            cnt[a%100/10]++;
            cnt[a%10]++;

            b = j % 100 / 10 * i;
            if(b > 999)
                continue;
            cnt[b/100]++;
            cnt[b%100/10]++;
            cnt[b%10]++;

            c = j / 100 * i;
            if(c > 999)
                continue;
            cnt[c/100]++;
            cnt[c%100/10]++;
            cnt[c%10]++;

            d = a + b * 10 + c * 100;
            if(d < 100000)
            {
                cnt[d/10000]++;
                cnt[d%10000/1000]++;
                cnt[d%1000/100]++;
                cnt[d%100/10]++;
                cnt[d%10]++;

                ok = 1;
                for(k=0; k<=9; k++)
                {
                    if(cnt[k] > 2)
                    {
                        ok = 0;
                        break;
                    }
                }
             if(ok == 1)
                {
                    printf("%d %d\n", i, j);
                    out = 0;
                }
            }
        }
    }
    t = clock();
    printf("time: %dMS\n", t-s);
    return 0;
}


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载