思路:
1. 用一个 hash[ ] 数组存放输入的数字,令 hash[ tmp ]=1 。
2. 一个自定义函数 check( ) ,检查各位是否为输入的数字。
3. 暴搜。第一行数从 100到999,第二行数从 10到99。
4. 剪枝。
代码:
/*
ID: who jay
LANG: C++
TASK: crypt1
*/
#include<stdio.h>
bool hash[10]= {0};
bool check(int i)
{
while(i)
{
if(!hash[i%10])
return 1;
i/=10;
}
return 0;
}
int main()
{
freopen("crypt1.in","r",stdin);
freopen("crypt1.out","w",stdout);
int n,i,j,tmp,f1,f2,f3,s;
while(scanf("%d",&n)!=EOF)
{
for(i=0; i<n; i++)
{
scanf("%d",&tmp);
hash[tmp]=1;
}
s=0;
for(i=100; i<1000; i++)
{
if(check(i)) continue;
for(j=10; j<100; j++)
{
f3=i*j;
if(f3>9999) break;
if(check(j)) continue;
if(check(f3)||f3<1000) continue;
f1=i*(j%10);
if(f1>999||check(f1)||f1<100) continue;
f2=i*(j/10);
if(f2>999||check(f2)||f2<100) continue;
s++;
}
}
printf("%d\n",s);
}
fclose(stdin);
fclose(stdout);
return 0;
}