usaco Prime Cryptarithm

遍历就行了。题目没给清楚其实他数字的个数不超过9个也就是不存在相同的数字。
/*
ID: jinbo wu
LANG:C++
TASK: crypt1
*/ 
#include<bits/stdc++.h>
using namespace std;
int a[10];
bool v[10];
bool judge(int x)
{
	while(x)
	{
		int t=x%10;
		if(!v[t])
		return false;
		x/=10;
	}
	return true;
}
void init(int n)
{
	int cnt=0;
	for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	for(int k=0;k<n;k++)
	for(int t1=0;t1<n;t1++)
	for(int t2=0;t2<n;t2++)
	{
		int sum=a[i]*10*10+a[j]*10+a[k];
		int x=sum*a[t2];
		if(x>999||!judge(x))
		continue;
		int y=sum*a[t1];
		if(y>999||!judge(y))
		continue;
		int temp=y*10+x;
		if(temp>9999||!judge(temp))
		continue;
		cnt++;
	}
	printf("%d\n",cnt);
}
int main()
{
	freopen("crypt1.in","r",stdin);
	freopen("crypt1.out","w",stdout);
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
	scanf("%d",&a[i]);
	v[a[i]]=1;
	} 
	init(n);
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值