遍历就行了。题目没给清楚其实他数字的个数不超过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);
}