Pagini recente » Profil ND2003 | Profil kyrk | Profil kyrk | Istoria paginii utilizator/dan.ghita | Cod sursa (job #38897)
Cod sursa(job #38897)
var a:array[1..100000]of integer;
b:array[1..100000]of int64;
d:int64;
z,x,i,e:longint;
c:char;
function dmare:boolean;
var i:longint;
begin
dmare:=false;
if z>x then exit;
if x>z then
begin
dmare:=true;
exit;
end;
for i:=z downto 1 do
begin
if a[i]>b[i] then exit;
if b[i]>a[i] then
begin
dmare:=true;
exit;
end;
end;
dmare:=true;
end;
procedure adunare;
var i:longint;
t:int64;
begin
t:=d;
i:=0;
while t>0 do
begin
i:=i+1;
if i>x then x:=x+1;
b[i]:=b[i]+t;
t:=b[i] div 10;
b[i]:=b[i] mod 10;
end;
if dmare then
begin
exit;
end
else adunare;
end;
begin
assign(input,'next.in');
reset(input);
assign(output,'next.out');
rewrite(output);
while not eoln do
begin
read(c);
z:=z+1;
a[z]:=ord(c)-ord('0');
end;
for i:=1 to z div 2 do
begin
e:=a[i];
a[i]:=a[z+1-i];
a[z+1-i]:=e;
end;
readln;
readln(d);
if (d=1)or(d=2)and(z>6) then
begin
x:=z;
for i:=1 to z do b[i]:=a[i];
end;
if d>2 then adunare;
for i:=x downto 1 do
begin
if (i=1)and(d=2)and(a[z] mod 2=1)and(z>6) then
begin
write(b[i]+1);
break;
end;
write(b[i]);
end;
close(output);
end.