PASCAL编程问题
一道PASCAL程序题,输入a1,a2,a3,....a20将它们从小到大排序后输出,并给出现在每个元素所对应的原来次序。例如输入27,3,25,27,14,39输出32...
一道PASCAL程序题,输入a1,a2,a3,....a20将它们从小到大排序后输出,并给出现在每个元素所对应的原来次序。例如输入27,3,25,27,14,39
输出
3 2
14 5
25 3
27 1
27 4
为什么回答的每个程序都在一个差不多的地方出错???有没有正确的???? 展开
输出
3 2
14 5
25 3
27 1
27 4
为什么回答的每个程序都在一个差不多的地方出错???有没有正确的???? 展开
13个回答
展开全部
var
a:array[1..100,1..100] of longint;
i,j,k,n:longint;
begin
read(n);
for i:=n downto n div 2 do
begin
for j:=n-i+1 to i do
begin
inc(k);
a[n-i+1,j]:=k;
end;
for j:=n-i+2 to i do
begin
inc(k);
a[j,i]:=k;
end;
for j:=i-1 downto n-i+1 do
begin
inc(k);
a[i,j]:=k;
end;
for j:=i-1 downto n-i+2 do
begin
inc(k);
a[j,n-i+1]:=k;
end;
end;
if n mod 2=1 then a[n div 2+1,n div 2+1]:=n*n;
for i:=1 to n do
begin
for j:=1 to n do
write(a[i,j],' ');
writeln;
end;
end.
a:array[1..100,1..100] of longint;
i,j,k,n:longint;
begin
read(n);
for i:=n downto n div 2 do
begin
for j:=n-i+1 to i do
begin
inc(k);
a[n-i+1,j]:=k;
end;
for j:=n-i+2 to i do
begin
inc(k);
a[j,i]:=k;
end;
for j:=i-1 downto n-i+1 do
begin
inc(k);
a[i,j]:=k;
end;
for j:=i-1 downto n-i+2 do
begin
inc(k);
a[j,n-i+1]:=k;
end;
end;
if n mod 2=1 then a[n div 2+1,n div 2+1]:=n*n;
for i:=1 to n do
begin
for j:=1 to n do
write(a[i,j],' ');
writeln;
end;
end.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Program dzl;
Var a,b:array[1..20]of integer;
i,j,n,t:integer;
Begin
Readln(n);
For i:=1 to n Do
Begin
Read(a[i]);
b[i]:=i;
End;
For i:=1 to n-1 Do
For j:=i+1 to n Do
If a[i]>a[j] then
Begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
t:=b[i];
b[i]:=b[j];
b[j]:=t;
End;
For i:=1 to n Do
Writeln(a[i],' ',b[i]);
End.
Var a,b:array[1..20]of integer;
i,j,n,t:integer;
Begin
Readln(n);
For i:=1 to n Do
Begin
Read(a[i]);
b[i]:=i;
End;
For i:=1 to n-1 Do
For j:=i+1 to n Do
If a[i]>a[j] then
Begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
t:=b[i];
b[i]:=b[j];
b[j]:=t;
End;
For i:=1 to n Do
Writeln(a[i],' ',b[i]);
End.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
var a,b:array[1..20] of integer;
n,i,j,k:integer;
begin
readln(n);
for i:=1 to n do
begin
read(a[i]);
b[i]:=i;
end;
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]>a[j] then
begin
k:=a[i];
a[i]:=a[j];
a[j]:=k;
k:=b[i];
b[i]:=b[j];
b[j]:=k;
end;
for i:=1 to n do writeln(a[i]:5,b[i]:5);
end.
n,i,j,k:integer;
begin
readln(n);
for i:=1 to n do
begin
read(a[i]);
b[i]:=i;
end;
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]>a[j] then
begin
k:=a[i];
a[i]:=a[j];
a[j]:=k;
k:=b[i];
b[i]:=b[j];
b[j]:=k;
end;
for i:=1 to n do writeln(a[i]:5,b[i]:5);
end.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
for i:=1 to n do
readln(a[i])
冒泡排序
for i:=1 to n do
begin
if i mod 5=0
then wrireln
wtire ('a',i,'=',a[i]);
end;
readln(a[i])
冒泡排序
for i:=1 to n do
begin
if i mod 5=0
then wrireln
wtire ('a',i,'=',a[i]);
end;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
记录下标就好了,很容易实现啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询