记录编号 69449 评测结果 AAAAAAAAAA
题目名称 [金陵中学2007] 吉祥数 最终得分 100
用户昵称 Gravatar铁策 是否通过 通过
代码语言 Pascal 运行时间 0.004 s
提交时间 2013-09-15 18:49:28 内存使用 0.17 MiB
显示代码纯文本
program P617;
label 1;
type
arr=array[1..200] of longint;
const
p:array[0..9,1..9] of longint=
((0,0,0,0,0,0,0,0,0),
 (1,1,1,1,1,1,1,1,1),
 (2,4,8,16,32,64,128,256,512),
 (3,9,27,81,243,729,2187,6561,19683),
 (4,16,64,256,1024,4096,16384,65536,262144),
 (5,25,125,625,3125,15625,78125,390625,1953125),
 (6,36,216,1296,7776,46656,279936,1679616,10077696),
 (7,49,343,2401,16807,117649,823543,5764801,40353607),
 (8,64,512,4096,32768,262144,2097152,16777216,134217728),
 (9,81,729,6561,59049,531441,4782969,43046721,387420489));
var
a,b,ls:arr;
i,j,n,m,k,l,c,x:longint;
function ans(a:longint; s:integer):longint;
begin
case a of
0..9:ans:=p[a,s];
10..99:ans:=p[a div 10,s]+p[a mod 10,s];
100..999:ans:=p[a div 100,s]+p[(a mod 100) div 10,s]+p[a mod 10,s];
end;
end;
procedure find(i:integer);
var
j,k:integer;
begin
k:=0;
for j:=1 to c do if a[i]=b[j] then k:=1;
if k=1 then begin for j:=i to m-1 do ls[j]:=ls[j+1];  ls[m]:=0;
dec(m);   x:=1;   end else x:=0;
end;
procedure swap(var a,b:longint);
var
c:longint;
begin
c:=a; a:=b; b:=c;
end;
begin
assign(input,'ghillie.in');
reset(input);
assign(output,'ghillie.out');
rewrite(output);
readln(n);
while not(eof) do begin inc(m); read(a[m]) end;
c:=m;
for i:=1 to n do
begin
ls:=a;
for j:=1 to m do b[j]:=ans(a[j],i+1);
for j:=1 to m do
begin
  1:find(j);
  if  x=1 then begin a:=ls; goto 1; end;
  end;
end;

for i:=1 to m-1 do
  for j:=i+1 to m do
  if  a[i]>a[j] then swap(a[i],a[j]);
for i:=1 to m do write(a[i],' ');
writeln;
end.