用1-9组成三个三位数abc,def,ghi,每个数字只能使用一次,并且要求abc:def:ghi=1:2:3...

//判断有没有重复的数字
int fun(int a[],int b[],int c[])
{
   for(int i=0;i<3;i++)
   {
      for(int j=0;j<3;j++)
      {
          for(int k=0;k<3;k++)
          {
              if(a[i]==b[j]||a[i]==c[k]||b[j]==c[k])
                  return 0;
          }
      }
   }
   return 1;
}


int main()
{
   int one,two,three;
   int a[3],b[3],c[3];
   int i,j,k;
   for(i=123;i<350;i++)
   {
      one=i;
      a[0]=one/100;                  
      a[1]=(one%100)/10;
      a[2]=one%10;
      if(a[0]==a[1]||a[1]==a[2]||a[0]==a[2])     //不能有重复的数字
          continue;
      for(j=246;j<700;j++)
      {
          two=j;
          b[0]=two/100;
          b[1]=two%100/10;
          b[2]=two%10;
          if(b[0]==a[1]||b[1]==b[2]||b[0]==b[2])
              continue;
          for(k=369;k<1000;k++)
          {
              three=k;
              c[0]=three/100;
              c[1]=three%100/10;
              c[2]=three%10;
              if(c[0]==c[1]||c[1]==c[2]||c[0]==c[2])
                  continue;
              if(fun(a,b,c))
                  if(one*3==three&&one*2==two)
                      printf("%d %d %d\n",one,two,three);
          }
      }
   }
}

 

转载于:https://www.cnblogs.com/mrheyao/archive/2013/03/20/2970966.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值