解释程序(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/08/27 13:06:16
![解释程序(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](/uploads/image/z/11581020-36-0.jpg?t=%E8%A7%A3%E9%87%8A%E7%A8%8B%E5%BA%8F%EF%BC%88NOIP2009%E6%99%AE%E5%8F%8A%E7%BB%84%E5%88%9D%E8%B5%9B%E8%AF%95%E9%A2%98%EF%BC%89vara%2Cb%3Aarray%5B0..2%5D+of+integer%3Bi%2Cj%2Ctmp%3Ainteger%3Bbeginfor+i+%3A%3D+0+to+2+doread%28b%5Bi%5D%29%3Bfor+i+%3A%3D+0+to+2+dobegina%5Bi%5D+%3A%3D+0%3Bfor+j+%3A%3D+0+to+i+dobegininc%28a%5Bi%5D%2Cb%5Bj%5D%29%3Binc%28b%5Ba%5Bi%5D+mod+3%5D%2Ca%5Bj%5D%29%3Bend%3Bend%3Btmp+%3A%3D+1%3Bfor+i+%3A%3D+0)
解释程序(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比直接加减稍快.