比赛 20101101 评测结果 WWWWWWWAAW
题目名称 漂亮字串 最终得分 20
用户昵称 donny 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-01 20:03:20
显示代码纯文本
program bs;
var
  i,j,k,l:longint;
  x,xx,o,oo:longint;
  s,ss,m,mm:longint;
function suan(x,y:longint):longint;
var
  i:longint;
begin
  i:=x mod y;
  if i=0 then exit(x div y)
  else exit((x div y)+1);
end;
procedure find;
var
  i,j,k:longint;
begin
  if ((ss<m)and(s>m))or((ss<mm)and(s>m))or((mm>ss)and(m<s))or((mm<s)and(m>s)) then
    writeln(x+o)
    else
    begin
      if ss>m then
      begin
        writeln(o+(m+1)*xx);
      end
      else
      begin
        writeln(x+(s+1)*oo);
      end;
    end;
end;
begin
  assign(input,'bs.in');
  reset(input);
  assign(output,'bs.out');
  rewrite(output);
  while not eof do
  begin
    readln(x,o,xx,oo);
    if x=0 then
    begin
      writeln(oo);
      close(input);
      close(output);
      halt;
    end;
    if o=0 then
    begin
      writeln(xx);
      close(input);
      close(output);
      halt;
    end;
    if xx=0 then
    begin
      writeln(oo);
      close(input);
      close(output);
      halt;
    end;
    if oo=0 then
    begin
      writeln(xx);
      close(input);
      close(output);
      halt;
    end;
    s:=x;
    ss:=suan(x,xx);
    m:=o;
    mm:=suan(o,oo);
    find;
  end;
  close(input);
  close(output);
end.