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.

题外话:我帮你整理了包括 AI 写作、绘画、视频(自媒体制作)零门槛 AI 课程 + 国内可直接顺畅使用的软件。想让自己快速用上 AI 工具来降本增效,辅助工作和生活?限时报名

当前页阅读量为: