// PascalABC.NET 3.1, сборка 1200 от 13.03.2016 begin var a:=MatrixRandom(7,7,0,9); var k:=0; for var i:=0 to 6 do begin for var j:=0 to 6 do begin Write(a[i,j]:3); if a[i,j] in [1..5] then Inc(k) end; Writeln end; Writeln('Кол-во элементов на [1,5]: ',k) end.
const n=7; var a:array[1..n,1..n] of integer; i,j,k:integer; begin Randomize; k:=0; for i:=1 to n do begin for j:=1 to n do begin a[i,j]:=Random(10); Write(a[i,j]:3); if a[i,j] in [1..5] then Inc(k) end; Writeln end; Writeln('Кол-во элементов на [1,5]: ',k) end.
begin
var a:=MatrixRandom(7,7,0,9);
var k:=0;
for var i:=0 to 6 do begin
for var j:=0 to 6 do begin
Write(a[i,j]:3);
if a[i,j] in [1..5] then Inc(k)
end;
Writeln
end;
Writeln('Кол-во элементов на [1,5]: ',k)
end.
Тестовое решение:
2 1 7 3 3 2 7
9 2 9 2 0 5 5
4 2 6 9 4 6 0
1 0 3 5 4 5 9
6 3 6 0 2 0 8
0 8 4 3 2 1 8
6 0 4 4 5 4 0
Кол-во элементов на [1,5]: 27
Вариант "совсем для школы"
const
n=7;
var
a:array[1..n,1..n] of integer;
i,j,k:integer;
begin
Randomize;
k:=0;
for i:=1 to n do begin
for j:=1 to n do begin
a[i,j]:=Random(10);
Write(a[i,j]:3);
if a[i,j] in [1..5] then Inc(k)
end;
Writeln
end;
Writeln('Кол-во элементов на [1,5]: ',k)
end.
from itertools import product
i = open('input.txt', 'r')
o = open('output.txt', 'w+')
l = int(i.
alpha = "245"
d = []
for s in product(alpha, repeat=l):
d.append([" ".join(
for q in d[1: ]:
s = " ".join(q)
if int(s.count('2')) > 2:
continue
o.write(" ".join(q) + '\n')
i.close()
o.close()
код к : «перевод кода с питона на паскаль»
var
n,c,i,ost,b,t,d: integer;
a,k: string;
begin
readln(n);
c: =1;
for i: =1 to n do
c: =c*3;
c: =c-1;
for i: =1 to c do
begin
k: ='';
b: =i;
t: =0;
while b> 0 do
begin
ost: =b mod 3;
if ost=0 then inc(t);
d: =(-sqr(ost)+5*ost+4)div 2;
str(d,a);
k: =a+k;
b: =b div 3;
end;
while length(k)do
begin
k: ='2'+k;
inc(t);
end;
if t< =2 then writeln(k);
end;
end.