clove_ck 2013-10-21 04:27:00
点我顶贴
收藏
删除
为什么第二个点总是过不去?
这不科学!!!
var n,r,a,c:integer;
s:string;
///////////////////////////////// p295
begin
while not eof do
begin
readln(n,r);
s:='';
a:=n;
while a<>0 do
begin
if a>0 then
begin
c:=a mod r;
a:=a div r;
if c<10 then s:=chr(c+ord('0'))+s
else s:=chr(c+ord('A')-10)+s;
end
else
begin
c:=a mod r;
if c=0 then begin
s:='0'+s;
a:=a div r;
end
else begin
c:=c-r;
a:=(a div r)+1;
if c<10 then s:=chr(c+ord('0'))+s
else s:=chr(c+ord('A')-10)+s;
end;
end;
end;
writeln(n,'=',s,'(base',r,')');
end;
end.