pascal程序(初级)
答案:3 悬赏:80 手机版
解决时间 2021-02-11 21:20
- 提问者网友:十年饮冰
- 2021-02-11 13:20
pascal程序(初级)
最佳答案
- 五星知识达人网友:荒野風
- 2021-02-11 14:46
冒泡,楼上的记住是冒泡,你快排木有用。
var i,j,t,n:longint;
st:string;
a,b:array[1..100]of longint;
c:array[1..100] of string;
bj:boolean;
begin
read(n);
for i:=1to n do
begin
read(ch);
while ch<>' ' do
begin
c[i]:=c[i]+ch;
read(ch);
end;
readln(b[i],a[i]);
end;
for i:=1to n-1do
begin
bj:=false;
for j:=1to n-i do
begin
if a[j]>a[j+1]then
begin
bj:=true;
t:=a[j];
a[j]:=a[j+1];
a[j+1]:=t;
t:=b[j];
b[j]:=b[j+1];
b[j+1]:=t;
st:=c[j];
c[j]:=c[j+1];
c[j+1]:=st;
end;
end;
if not bj then break;
end;
for i:=1 to n do
write(a[i],' ');
end.
望采纳
var i,j,t,n:longint;
st:string;
a,b:array[1..100]of longint;
c:array[1..100] of string;
bj:boolean;
begin
read(n);
for i:=1to n do
begin
read(ch);
while ch<>' ' do
begin
c[i]:=c[i]+ch;
read(ch);
end;
readln(b[i],a[i]);
end;
for i:=1to n-1do
begin
bj:=false;
for j:=1to n-i do
begin
if a[j]>a[j+1]then
begin
bj:=true;
t:=a[j];
a[j]:=a[j+1];
a[j+1]:=t;
t:=b[j];
b[j]:=b[j+1];
b[j+1]:=t;
st:=c[j];
c[j]:=c[j+1];
c[j+1]:=st;
end;
end;
if not bj then break;
end;
for i:=1 to n do
write(a[i],' ');
end.
望采纳
全部回答
- 1楼网友:枭雄戏美人
- 2021-02-11 17:02
program a001;
type
person = record
name : string;
id : integer;
point : integer;
end;
var
p : array[1..10000] of person;
n : integer;
procedure swap(var a,b:person); // 交换
var
t:person;
begin
t:=a;
a:=b;
b:=t;
end;
procedure sort(b,e:integer); // 快速排序
var
i,j:integer;
x:integer;
begin
i:=b;
j:=e;
x:=p[i].point;
repeat
while p[i].point>x do inc(i);
while p[j].point if i<=j then
begin
swap(p[i],a[j]);
inc(i);
dec(j);
end;
until i>j;
if i if j>b then sort(b,j);
end;
procedure readin; //读入数据
var
i:integer;
ch:char;
begin
readln(n);
for i:= 1 to n do
begin
read(ch);
while ch<>' ' do
begin
p[i].name:=p[i].name+ch;
read(ch);
end;
readln(p[i].id,p[i].point);
end;
end;
begin
readin;
sort(1,n);
for n:= 1 to n do
writeln(p[n].name,' ',p[n].id,' ',p[n].point);
end.
没编译过 应该对了追问大哥,请问哪一个是冒泡排序?
type
person = record
name : string;
id : integer;
point : integer;
end;
var
p : array[1..10000] of person;
n : integer;
procedure swap(var a,b:person); // 交换
var
t:person;
begin
t:=a;
a:=b;
b:=t;
end;
procedure sort(b,e:integer); // 快速排序
var
i,j:integer;
x:integer;
begin
i:=b;
j:=e;
x:=p[i].point;
repeat
while p[i].point>x do inc(i);
while p[j].point
begin
swap(p[i],a[j]);
inc(i);
dec(j);
end;
until i>j;
if i
end;
procedure readin; //读入数据
var
i:integer;
ch:char;
begin
readln(n);
for i:= 1 to n do
begin
read(ch);
while ch<>' ' do
begin
p[i].name:=p[i].name+ch;
read(ch);
end;
readln(p[i].id,p[i].point);
end;
end;
begin
readin;
sort(1,n);
for n:= 1 to n do
writeln(p[n].name,' ',p[n].id,' ',p[n].point);
end.
没编译过 应该对了追问大哥,请问哪一个是冒泡排序?
- 2楼网友:雪起风沙痕
- 2021-02-11 16:15
36+958741231
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯