pascal 简单题看看出了什麼问题
输出一个数组,让负数都排在正数左边,输出此数组和交换次数,看看我改变後为什麼会爆0varn,i,j,t,ans:integer;a:array[1..1000]ofint...
输出一个数组,让负数都排在正数左边,输出此数组和交换次数,看看我改变後为什麼会爆0var n,i,j,t,ans:integer; a:array[1..1000] of integer;beginreadln(n);for i:=1 to n do read(a[n]); i:=1; j:=n;repeatwhile a[i]<0 do="" while="">0 do dec(j);if i<j thenbegin t:=a[i]; a[i]:=a[j]; a[j]:=t; inc(i); dec(j); inc(ans);end;until i=j;for i:=1 to n do write(a[i]:3);writeln; writeln(ans);end.
var n,i,j,t,ans:integer; a:array[1..1000] of integer;beginreadln(n);for i:=1 to n do read(a[n]); i:=1; j:=n;repeatwhile a[i]<0 do inc(i);while a[j]>0 do dec(j);if i<j thenbegin t:=a[i]; a[i]:=a[j]; a[j]:=t; inc(i); dec(j); inc(ans);end;until i=j;for i:=1 to n do write(a[i]:3);writeln; writeln(ans);end. 展开
var n,i,j,t,ans:integer; a:array[1..1000] of integer;beginreadln(n);for i:=1 to n do read(a[n]); i:=1; j:=n;repeatwhile a[i]<0 do inc(i);while a[j]>0 do dec(j);if i<j thenbegin t:=a[i]; a[i]:=a[j]; a[j]:=t; inc(i); dec(j); inc(ans);end;until i=j;for i:=1 to n do write(a[i]:3);writeln; writeln(ans);end. 展开
3个回答
展开全部
var n,i,j,t,ans:integer;
a:array[1..1000] of integer;
begin
readln(n);for i:=1 to n do read(a[i]);
i:=1;
j:=n;.
repeat
while a[i]<0 do
do dec(j);
if i<j then
begin t:=a[i];
a[i]:=a[j];
a[j]:=t;
inc(i);
dec(j);
inc(ans);
end;
until i=j;
for i:=1 to n do write(a[i]:3);
writeln;
writeln(ans);
end.
var n,i,j,t,ans:integer;
a:array[1..1000] of integer;
begin
readln(n);
for i:=1 to n do read(a[n]);
i:=1;
j:=n;
repeat
while a[i]<0 do inc(i);
while a[j]>0 do dec(j);
if i<j then
begin t:=a[i];
a[i]:=a[j];
a[j]:=t; inc(i);
dec(j);
inc(ans);
end;
until i=j;
for i:=1 to n do write(a[i]:3);
writeln;
writeln(ans);
end.
a:array[1..1000] of integer;
begin
readln(n);for i:=1 to n do read(a[i]);
i:=1;
j:=n;.
repeat
while a[i]<0 do
do dec(j);
if i<j then
begin t:=a[i];
a[i]:=a[j];
a[j]:=t;
inc(i);
dec(j);
inc(ans);
end;
until i=j;
for i:=1 to n do write(a[i]:3);
writeln;
writeln(ans);
end.
var n,i,j,t,ans:integer;
a:array[1..1000] of integer;
begin
readln(n);
for i:=1 to n do read(a[n]);
i:=1;
j:=n;
repeat
while a[i]<0 do inc(i);
while a[j]>0 do dec(j);
if i<j then
begin t:=a[i];
a[i]:=a[j];
a[j]:=t; inc(i);
dec(j);
inc(ans);
end;
until i=j;
for i:=1 to n do write(a[i]:3);
writeln;
writeln(ans);
end.
展开全部
你好!
说实在的,你写的这玩意……
要是能过就怪了……
你看起来用了快排的思想
但是坑爹的是你读的数组是错的……
for i:=1 to n do read(a[n]);
你一直在读a[n]啊!!!
不说了。。。
望采纳,谢谢!
说实在的,你写的这玩意……
要是能过就怪了……
你看起来用了快排的思想
但是坑爹的是你读的数组是错的……
for i:=1 to n do read(a[n]);
你一直在读a[n]啊!!!
不说了。。。
望采纳,谢谢!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
var n,i,j,t,ans:integer;
a:array[1..1000] of integer;
begin
readln(n);
for i:=1 to n do read(a[n]);
i:=1;
j:=n;
repeat
while a[i]<0 do
inc(i);
while a[j]>0 do
dec(j);
if i<j then
begin t:=a[i];
a[i]:=a[j];
a[j]:=t;
inc(i);
dec(j);
inc(ans);
end;
until i=j;
for i:=1 to n do write(a[i]:3);writeln; writeln(ans);
end.
这样行不行?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询