模拟除法的竖式运算。

 

 

 

 

var
  s:string;
  b,m,len,i,n:longint;
  a,c:array[1..1000] of integer;
begin
  readln(s);
  readln(b);
  len:=length(s);
  for i:=1 to len do  a[i]:=ord(s[len-i+1])-48;
  m:=0;
  for i:=len downto 1 do
    begin
      c[i]:=(m*10+a[i])div b;    //记录商
      m:=(m*10+a[i]) mod b;      //求余数
    end;
  while (len>0)and (c[len]=0) do  dec(len);//去除首位的0
  if len=0 then write(0)  
  else
    for i:=len downto 1 do write(c[i]);
  writeln;
  writeln('remainder:',m);//输出余数
end.
View Code