1. "Традиционный" вариант //PascalABC.Net 3.0, сборка 1052 function NOD(a, b: longint): longint; begin while a <> b do if a > b then a := a - b else b := b - a; NOD := a end;
var f: Text; tNOD: longint;
begin Assign(f, 'input.txt'); Reset(f); if not Eof(f) then Readln(f, tNOD); var n: longint := 1; while (not Eof(f)) and (n > 0) and (tNOD > 1) do begin Readln(f, n); if n <> 0 then tNOD := NOD(tNOD, n) end; Close(f); Assign(f, 'output.txt'); Rewrite(f); Writeln(f,tNOD); Close(f) end.
2. "Современный" вариант //PascalABC.Net 3.0, сборка 1052 function NOD(a, b: integer): integer; begin while a <> b do if a > b then a -= b else b -= a; Result := a end;
var tNOD: integer := 0; n: integer;
begin foreach var sn in Readlines('input.txt') do begin n := StrToInt(sn); if tNOD = 0 then tNOD := n else if n = 0 then break else tNOD := NOD(tNOD, n); end; WriteAllText('output.txt', IntToSTR(tNOD)); end.
Пример файла input.txt находится во вложении, контрольный результат 4096
Var i, j, k : integer; a : array [0..9,0..9] of char; procedure U(i,j:integer); var c : char; begin c:=a[i,j]; a[i,j]:=' '; if (c='W')and(a[i+1,j]='B') then U(i+1,j); if (c='B')and(a[i+1,j]='W') then U(i+1,j); if (c='W')and(a[i-1,j]='B') then U(i-1,j); if (c='B')and(a[i-1,j]='W') then U(i-1,j); if (c='W')and(a[i,j+1]='B') then U(i,j+1); if (c='B')and(a[i,j+1]='W') then U(i,j+1); if (c='W')and(a[i,j-1]='B') then U(i,j-1); if (c='B')and(a[i,j-1]='W') then U(i,j-1); end; begin assign(input,'input.txt'); reset(input); assign(output,'output.txt'); rewrite(output); for i:=1 to 8 do begin for j:=1 to 8 do read(a[i,j]); readln end; for i:=1 to 8 do begin a[0,i]:=' '; a[9,i]:=' '; a[i,0]:=' '; a[i,9]:=' ' end; k:=0; for i:=1 to 8 do for j:=1 to 8 do if a[i,j]<>' ' then begin k:=k+1; U(i,j) end; write(k); close(output) end.
//PascalABC.Net 3.0, сборка 1052
function NOD(a, b: longint): longint;
begin
while a <> b do if a > b then a := a - b else b := b - a;
NOD := a
end;
var
f: Text;
tNOD: longint;
begin
Assign(f, 'input.txt'); Reset(f);
if not Eof(f) then Readln(f, tNOD);
var n: longint := 1;
while (not Eof(f)) and (n > 0) and (tNOD > 1) do
begin
Readln(f, n);
if n <> 0 then tNOD := NOD(tNOD, n)
end;
Close(f);
Assign(f, 'output.txt'); Rewrite(f);
Writeln(f,tNOD);
Close(f)
end.
2. "Современный" вариант
//PascalABC.Net 3.0, сборка 1052
function NOD(a, b: integer): integer;
begin
while a <> b do if a > b then a -= b else b -= a;
Result := a
end;
var
tNOD: integer := 0;
n: integer;
begin
foreach var sn in Readlines('input.txt') do
begin
n := StrToInt(sn);
if tNOD = 0 then tNOD := n
else
if n = 0 then break else tNOD := NOD(tNOD, n);
end;
WriteAllText('output.txt', IntToSTR(tNOD));
end.
Пример файла input.txt находится во вложении, контрольный результат 4096