记录编号 33605 评测结果 AAAAAAAAAA
题目名称 [金陵中学2007] 吉祥数 最终得分 100
用户昵称 Gravatar苏轼 是否通过 通过
代码语言 C++ 运行时间 0.000 s
提交时间 2011-11-11 15:43:59 内存使用 0.27 MiB
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int n,q[201],w[201];
int p=0;
int f[10][9]={{0},{1,1,1,1,1,1,1,1,1},
{1,2,4,8,16,32,64,128,256},
{1,3,9,27,81,243,729,2187,6561},
{1,4,16,64,256,1024,4096,16384,65536},
{1,5,25,125,625,3125,15625,78125,390625},
{1,6,36,216,1296,7776,46656,279936,1679616},
{1,7,49,343,2401,16807,117649,823543,5764801},
{1,8,64,512,4096,32768,262144,2097152,16777216},
{1,9,81,729,6561,59049,531441,4782969,43046721}};
int cmp(const void *a,const void *b);
bool check(int x);
int find(int x,int y);
int main()
{
	freopen ("ghillie.in","r",stdin);
	freopen ("ghillie.out","w",stdout);
	scanf("%d",&n);
	while (cin>>q[p])
	{
		p++;
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=0;j<p;j++)
		{
			w[j]=find(q[j],i);
		}
		for (int k=0;k<p;k++)
		{
			if (check(q[k]))
			{
				q[k]=-1;
			}
		}
		for (int u=0;u<p;u++)
		{
			if (q[u]==-1)
			{
				for (int y=u;y<p-1;y++)
				{
					q[y]=q[y+1];
				}
				p--;
				u--;
			}
		}
	}
	qsort(q,p,sizeof(q[0]),cmp);
	for (int i=0;i<p;i++)
	{
		cout<<q[i]<<' ';
	}
	return 0;
}
int find(int x,int y)
{
	int a,b,temp=0;
	a=x;
	b=10;
	while (a>0)
	{
		temp+=f[(a%10)][y+1];
		a=a/10;
	}
	return temp;
}
bool check(int x)
{
	for (int i=0;i<p;i++)
	{
		if (x==w[i])
		{
			return  true;
		}
	}
	return false;
}
int cmp(const void *a,const void *b)
{
	return  *(int *)a - *(int *)b;
}