0
点赞
收藏
分享

微信扫一扫

P1211 [USACO1.3]牛式 Prime Cryptarithm

boomwu 2022-02-05 阅读 27

P1211 [USACO1.3]牛式 Prime Cryptarithm - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

#include<bits/stdc++.h>

using namespace std;

int a[10], n; //a[10]为桶数组

bool check(int x, int y) //检查x是否是符合条件的y位数
{
if(x >= pow(10,y)) return false;//判断位数
while(x > 0)
{
if(a[x % 10] == 0) return false; //判断枚举的数是不是在题目给定的数集中
x /= 10;
}
return true;
}
int main()
{
scanf("%d",
int t, cnt = 0;
for(int i = 1; i <= n; i++)
{
scanf("%d",
a[t] = 1;
}

for(int i = 111; i <= 999; i++) //枚举所有的三位数
for(int j = 11; j <= 99; j++) //枚举所有的两位数
if(check(i,3) && check(j,2) && check(i * (j % 10),3) && check(i * (j / 10), 3) && check((i * j),4))
cnt++;

printf("%d",cnt);
return 0;
}
举报

相关推荐

0 条评论