USACO 1.2 Dual Palindromes 双重回文数 程序

Compiling… Compile: OK

Executing…

Keep up the good work!

Thanks for your submission!

{
ID:ceeji
PROB:dualpal
LANG:PASCAL
}
//By Ceeji
//Date: 2009-6-1
//Type: NO
//Resource: USACO 1.2
Program dualpal;
Const
   fin='dualpal.in';
   fou='dualpal.out';
Var
   i,n,s,ss:longint;
Function translate(i,b: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;
Function isok(ii:longint):boolean;
var j,k:longint;
begin
   k:=0;
   for j:=2 to 10 do
   begin
     if ishuiwen(translate(ii,j)) then inc(k);
     if k=2 then exit(true);
   end;
   exit(false);
end;
begin
   assign(input,fin);  reset(input);
   assign(output,fou); rewrite(output);
   readln(n,s);
   close(input); ss:=0; i:=s+1;
   while ss<n do
   begin
      if isok(i) then begin inc(ss); writeln(i); end;
      inc(i);
   end;
   close(output);
end.
当前页阅读量为: