2. 班长的任务

program ex_2;
var
        t, n, i, j : integer;
        a : array[1 .. 2, 1 .. 60] of integer;
        noswap : boolean;
begin
        readln(n);
        for i := 1 to n do
                read(a[1, i]);
        for i := 1 to n do
                read(a[2, i]);
        for i := 1 to n do
        begin
                noswap := true;
                for j := 1 to n-i do
                        if (a[1, j] > a[1, j+1]) or ((a[1, j] = a[1, j+1]) and (a[2, j] > a[2, j+1])) then
                        begin
                                t := a[1, j];
                                a[1, j] := a[1, j+1];
                                a[1, j+1] := t;
                                t := a[2, j];
                                a[2, j] := a[2, j+1];
                                a[2, j+1] := t;
                                noswap := false;
                        end;
                if (noswap) then break;
        end;
        for i := 1 to n do
                write(a[1, i], '  ');
        writeln;
        for i := 1 to n do
                write(a[2, i], '  ');
        writeln;
        readln;
        readln;
end.
posted @ 2010-03-04 14:51  SmartIOI  阅读(179)  评论(0)    收藏  举报
本站采用CC授权如需转载、引用文章,请务必附上作者及来源处。 Creative Commons License