主题:[讨论]帮忙解释2个题目
帮忙解释2个题目:
⑴program program4;
var c: array[1..3] of string[200];
s: array[1..10] of integer;
m, n, i: integer;
procedure numara;
var cod: boolean;
i, j, nr: integer;
begin
for j := 1 to n do begin
nr := 0; cod := true;
for i := 1 to m do
if c[i, j] = '1' then begin
if not cod then begin
cod := true; inc(s[nr]); nr := 0;
end
end
else begin
if cod then begin
nr := 1; cod := false;
end
else inc(nr);
end;
if not cod then inc(s[nr]);
end;
end;
begin
readln(m, n);
for i := 1 to m do readln(c[i]);
numara;
for i := 1 to m do
if s[i] <> 0 then write(i, ' ', s[i], ' ');
end.
输入:
3 10
1110000111
1100001111
1000000011
输出:
⑵program program4;
const
u: array[0..2] of integer = (1,-3,2);
v: array[0..1] of integer = (-2,3);
var
i, n, sum: integer;
function g(n: integer): integer
var i, sum: integer;
begin
sum :=0;
for i := 1 to n do inc(sum, u[i mod 3]*i);
g := sum;
end;
begin
sum := 0;
read(n);
for i := 1 to n do inc(sum, v[i mod 2] * g(i))
writeln(sum);
end.
输入: 103
输出?
求详细过程,感谢
⑴program program4;
var c: array[1..3] of string[200];
s: array[1..10] of integer;
m, n, i: integer;
procedure numara;
var cod: boolean;
i, j, nr: integer;
begin
for j := 1 to n do begin
nr := 0; cod := true;
for i := 1 to m do
if c[i, j] = '1' then begin
if not cod then begin
cod := true; inc(s[nr]); nr := 0;
end
end
else begin
if cod then begin
nr := 1; cod := false;
end
else inc(nr);
end;
if not cod then inc(s[nr]);
end;
end;
begin
readln(m, n);
for i := 1 to m do readln(c[i]);
numara;
for i := 1 to m do
if s[i] <> 0 then write(i, ' ', s[i], ' ');
end.
输入:
3 10
1110000111
1100001111
1000000011
输出:
⑵program program4;
const
u: array[0..2] of integer = (1,-3,2);
v: array[0..1] of integer = (-2,3);
var
i, n, sum: integer;
function g(n: integer): integer
var i, sum: integer;
begin
sum :=0;
for i := 1 to n do inc(sum, u[i mod 3]*i);
g := sum;
end;
begin
sum := 0;
read(n);
for i := 1 to n do inc(sum, v[i mod 2] * g(i))
writeln(sum);
end.
输入: 103
输出?
求详细过程,感谢