# Код на ruby 2.2.3p173 def zadanie(jump1, jump2) min = jump1 for i in 1..1000 next if (i*jump1)%jump2 == 0 or (i*jump2)%jump1 == 0
if min > (i*jump1)%jump2 min = (i*jump1)%jump2 p [min, "#{i} * #{jump1} - #{i*jump1/jump2} * #{jump2}"] end
if min > (i*jump2)%jump1 min = (i*jump2)%jump1 p [min, "#{i} * #{jump2} - #{i*jump2/jump1} * #{jump1}"] end end return min end # # Примеры применения p zadanie(33, 55)
1) uses crt; var a:array [1..15] of integer; i,k:integer; begin randomize; k:=0; for i:=1 to 15 do begin a[i]:=random(10)-3; if (a[i]<0) then inc(k); write (a[i],' '); end; writeln; writeln (k/15*100,'%'); end.
2) uses crt; var a:array [1..20] of integer; i:integer; begin randomize; for i:=1 to 20 do begin a[i]:=random(30); write (a[i],' '); end; writeln; for i:=1 to 20 do if (a[i] mod 10 = 3) then write (a[i],' '); end.
3) uses crt; var a:array [1..20] of integer; i:integer; k:longint; begin randomize; k:=1; for i:=1 to 20 do begin a[i]:=random(30); write (a[i],' '); if (a[i]>9) and (a[i]<100) then k:=k*a[i]; end; writeln; writeln (k); end.
4) uses crt; var a:array [1..30] of integer; i:integer; flag:boolean; begin randomize; for i:=1 to 30 do begin a[i]:=random(30); write (a[i],' '); end; writeln; flag:=true; for i:=1 to 29 do if (a[i]>a[i+1]) then begin flag:=false; break; end; writeln (flag); end.
def zadanie(jump1, jump2)
min = jump1
for i in 1..1000
next if (i*jump1)%jump2 == 0 or (i*jump2)%jump1 == 0
if min > (i*jump1)%jump2
min = (i*jump1)%jump2
p [min, "#{i} * #{jump1} - #{i*jump1/jump2} * #{jump2}"]
end
if min > (i*jump2)%jump1
min = (i*jump2)%jump1
p [min, "#{i} * #{jump2} - #{i*jump2/jump1} * #{jump1}"]
end
end
return min
end
# # Примеры применения
p zadanie(33, 55)
Вывод
[22, "1 * 55 - 1 * 33"]
[11, "2 * 33 - 1 * 55"]
11
Т.е. минимум при 2 * 33 - 1 * 55 = 11
uses crt;
var a:array [1..15] of integer;
i,k:integer;
begin
randomize;
k:=0;
for i:=1 to 15 do
begin
a[i]:=random(10)-3;
if (a[i]<0) then inc(k);
write (a[i],' ');
end;
writeln;
writeln (k/15*100,'%');
end.
2)
uses crt;
var a:array [1..20] of integer;
i:integer;
begin
randomize;
for i:=1 to 20 do
begin
a[i]:=random(30);
write (a[i],' ');
end;
writeln;
for i:=1 to 20 do
if (a[i] mod 10 = 3) then write (a[i],' ');
end.
3)
uses crt;
var a:array [1..20] of integer;
i:integer;
k:longint;
begin
randomize;
k:=1;
for i:=1 to 20 do
begin
a[i]:=random(30);
write (a[i],' ');
if (a[i]>9) and (a[i]<100) then k:=k*a[i];
end;
writeln;
writeln (k);
end.
4)
uses crt;
var a:array [1..30] of integer;
i:integer;
flag:boolean;
begin
randomize;
for i:=1 to 30 do
begin
a[i]:=random(30);
write (a[i],' ');
end;
writeln;
flag:=true;
for i:=1 to 29 do
if (a[i]>a[i+1]) then
begin
flag:=false;
break;
end;
writeln (flag);
end.