USACO 1.2 Palindromic Squares 程序
{
ID:ceeji
PROB:palsquare
LANG:PASCAL
}
//By Ceeji
//Date: 2009-6-1
//Type: NO
//Resource: USACO 1.2
Program palsquare;
Const
fin='palsquare.in';
fou='palsquare.out';
Var
i,b:longint;
Function translate(i:longint):string;
var s:string;
j,p,k:longint;
begin
if i=0 then exit('0');
s:='';
j:=i;
while true do
begin
p:=j div b;
k:=j-p*b;
j:=p;
if (p=0) then
begin
if k<10 then s:=chr(48+k)+s
else s:=chr(55+k)+s;
exit(s);
end;
if k<10 then s:=chr(48+k)+s else s:=chr(55+k)+s;
end;
if s='' then exit('0');
end;
Function ishuiwen(s:string):boolean;
var i,l:longint;
s2:string;
begin
l:=length(s); s2:='';
for i:=l downto 1 do
begin
s2:=s2+s[i];
end;
if s2=s then exit(true) else exit(false);
end;
begin
assign(input,fin); reset(input);
assign(output,fou); rewrite(output);
readln(b);
close(input);
for i:=1 to 300 do
begin
if ishuiwen(translate(i*i)) then writeln(translate(i),' ',translate(i*i));
end;
close(output);
end.
© 轉載需附帶本文連結,依 CC BY-NC-SA 4.0 釋出。