题目: |
第3题:请写出程序运行后变量sum的值(6分)
program xx07_3;
const maxn=1000;
var pos,value:array[1..maxn]of longint;
n,i,j,x,sum:longint;
change:boolean;
begin
read(n);
for i:=1 to n do read(pos[i],value[i]);
change:=true;i:=1;
while change and (i<=n-1) do begin
change:=false;
for j:=1 to n-i do
if value[j]>value[j+1] then begin
change:=true;
x:=value[j];value[j]:=value[j+1];value[j+1]:=x;
end;
i:=i+1;
end;
sum:=0;
for i:=1 to n do sum:=sum+pos[i]*value[i];
writeln('sum=',sum);
end.
输入:
10
1 10
2 1
3 2
4 9
5 3
6 4
7 8
8 5
9 6
10 7
输出为:sum=_______ 输出:385
|