Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Task7;
- Uses sysutils;
- type
- arr = array[1..10, 1..10] of integer;
- var
- a : arr;
- l, dialog : integer;
- function randomInit() : arr;
- var
- i, j : integer;
- res : arr;
- begin
- randomize();
- for i := 1 to 10 do
- begin
- for j := 1 to 10 do
- begin
- res[i,j] := random(10);
- end;
- end;
- randomInit := res;
- end;
- function initFromKeyboard(): arr;
- var
- i, j : integer;
- res : arr;
- begin
- for i := 1 to 10 do
- begin
- for j := 1 to 10 do
- begin
- readln(res[i,j]);
- end;
- end;
- initFromKeyboard := res;
- end;
- function initFromFile(): arr;
- var
- i, j : integer;
- res : arr;
- s : string;
- f : textfile;
- begin
- assign(f,'in.txt');
- reset(f);
- for i := 1 to 10 do
- begin
- for j := 1 to 10 do
- begin
- readln(f,s);
- res[i,j] := StrToInt(s);
- end;
- end;
- close(f);
- initFromFile := res;
- end;
- procedure print(res : arr);
- var
- i, j : integer;
- begin
- for i := 1 to 10 do
- begin
- for j := 1 to 10 do
- begin
- write(res[i,j], ' ');
- end;
- writeln();
- end;
- end;
- function maxLine(a : arr) : integer;
- var
- i, j, maxi, max, cur : integer;
- begin
- cur := 0;
- maxi := 0;
- max := 0;
- for i := 1 to 10 do
- begin
- for j := 1 to 10 do
- begin
- cur := cur + a[i,j];
- end;
- if cur > max then
- begin
- max := cur;
- maxi := i;
- end;
- cur := 0;
- end;
- maxLine := maxi;
- end;
- procedure positionsOfMaxSum(a : arr);
- var
- i, j, max4, max4i, max4j, max8, max8i, max8j, cur : integer;
- begin
- max4:=0;
- max4i:=0;
- max4j:=0;
- max8:=0;
- max8i:=0;
- max8j:=0;
- for i := 1 to 10 do
- begin
- for j := 1 to 10 do
- begin
- if ((i - 1) > 0) and ((j - 1) > 0) and ((i + 1) < 11) and ((j + 1) < 11) then
- begin
- cur := a[i-1,j-1]+a[i-1,j]+a[i-1,j+1]+a[i,j+1]+a[i,j-1]+a[i+1,j+1]+a[i+1,j]+a[i+1,j-1];
- if cur > max8 then
- begin
- max8 := cur;
- max8i := i;
- max8j := j;
- end;
- cur := a[i-1,j]+a[i,j+1]+a[i,j-1]+a[i+1,j];
- if cur > max4 then
- begin
- max4 := cur;
- max4i := i;
- max4j := j;
- end;
- cur := 0;
- end;
- end;
- end;
- writeln('Для 4 соседей:', max4i,' ', max4j);
- writeln('Для 8 соседей:', max8i,' ', max8j);
- end;
- begin
- writeln('1)Случайная генерация');
- writeln('2)Клавиатурный ввод');
- writeln('3)Чтение из файла');
- readln(dialog);
- case(dialog) of
- 1:a:=randomInit();
- 2:a:=initFromKeyboard();
- 3:a:=initFromFile();
- end;
- print(a);
- writeln('1)Номер строки с максимальной суммой');
- writeln('2)Координаты элемента с максимальной суммой 4 соседей, 8 соседей');
- readln(dialog);
- case(dialog) of
- 1:writeln(maxLine(a));
- 2:positionsOfMaxSum(a);
- end;
- end.
Add Comment
Please, Sign In to add comment