猜算式

2、题目:猜算式
你一定还记得小学学习过的乘法计算过程,比如:

   179
x  224
------
   716
 358
358
------
40096
请你观察如下的乘法算式


    ***
x   ***
--------
    ***
   ***
  ***
--------
  *****
 
星号代表某位数字,注意这些星号中,
0~9中的每个数字都恰好用了2次。
(如因字体而产生对齐问题,请参看图p1.jpg)
请写出这个式子最终计算的结果,就是那个5位数是多少?

注意:只需要填写一个整数,不要填写任何多余的内容。比如说明文字。

#include<stdio.h>
#include<set>
using namespace std;
set<int>v1;
set<int>v2;
int check(int n)
{
	int tmp=n;
	int flag=1;
	while(tmp>0){
		if(v1.count(tmp%10)==1){
			if(v2.count(tmp%10)==1){
				flag=0;
				break;
			}else{
				v2.insert(tmp%10);
			}
		}else{
			v1.insert(tmp%10);
		}
		tmp=tmp/10;
	}
	return flag;
}
int main()
{
	int n,m;
	int flag=1;
	int tmp1,tmp2,tmp3;
	for(n=100;n<=990&&flag;n++)
	{
		for(m=100;m<=990&&flag;m++)
		{
			v1.clear();
			v2.clear();
			if(check(n)&&check(m)&&v1.count(0)==0&&v2.count(0)==0){
				tmp1=n*(m%10);
				if(!check(tmp1)){
					continue;
				}else{
					tmp2=n*(m/10%10);
					if(!check(tmp2)){
						continue;
					}else{
						tmp3=n*(m/100);
						if(!check(tmp3)){
							continue;
						}else if(check(m*n)){
							printf("%d * %d = %d\n",n,m,n*m);
							flag=0;
						}else{
							continue;
						}
					}	
				}		
			}
		}
	}
	return 0;
}---//40096


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值