解释程序(NOIP2009普及组初赛试题)vara,b:array[0..2] of integer;i,j,tmp:integer;beginfor i := 0 to 2 doread(b[i]);for i := 0 to 2 dobegina[i] := 0;for j := 0 to i dobegininc(a[i],b[j]);inc(b[a[i] mod 3],a[j]);end;end;tmp := 1;for i := 0
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/19 18:01:33
解释程序(NOIP2009普及组初赛试题)vara,b:array[0..2] of integer;i,j,tmp:integer;beginfor i := 0 to 2 doread(b[i]);for i := 0 to 2 dobegina[i] := 0;for j := 0 to i dobegininc(a[i],b[j]);inc(b[a[i] mod 3],a[j]);end;end;tmp := 1;for i := 0
解释程序(NOIP2009普及组初赛试题)
var
a,b:array[0..2] of integer;
i,j,tmp:integer;
begin
for i := 0 to 2 do
read(b[i]);
for i := 0 to 2 do
begin
a[i] := 0;
for j := 0 to i do
begin
inc(a[i],b[j]);
inc(b[a[i] mod 3],a[j]);
end;
end;
tmp := 1;
for i := 0 to 2 do
begin
a[i] := a[i] mod 10;
b[i] := b[i] mod 10;
tmp := tmp * (a[i] + b[i])
end;
writeln(tmp);
end.
写程序结果,输入2 3 5
其中
for i := 0 to 2 do
begin
a[i] := 0;
for j := 0 to i do
begin
inc(a[i],b[j]);
inc(b[a[i] mod 3],a[j]);
end;
解释程序(NOIP2009普及组初赛试题)vara,b:array[0..2] of integer;i,j,tmp:integer;beginfor i := 0 to 2 doread(b[i]);for i := 0 to 2 dobegina[i] := 0;for j := 0 to i dobegininc(a[i],b[j]);inc(b[a[i] mod 3],a[j]);end;end;tmp := 1;for i := 0
var
a,b:array[0..2] of integer;
i,j,tmp:integer;
begin
for i := 0 to 2 do
read(b[i]); //读入
for i := 0 to 2 do
begin
a[i] := 0;
for j := 0 to i do
begin
inc(a[i],b[j]); //a[i]:=a[i]+b[j]
inc(b[a[i] mod 3],a[j]); //b[a[i] mod 3]:=b[a[i] mod 3]+a[j]
end;
end;
tmp := 1;
for i := 0 to 2 do
begin
a[i] := a[i] mod 10;
b[i] := b[i] mod 10; //取余
tmp := tmp * (a[i] + b[i])
end;
writeln(tmp);
end.
真没什么可说的.这也不像是什么算法,估计就是专门写来出题的
inc函数那一段,inc(i,j)表示i:=i+j 如果写成inc(i)则表示i:=i+1
与之相对的dec函数用法相同,把+改成- inc dec比直接加减稍快.