作业帮 > 综合 > 作业

用free pascal来编个程序求数串的原始排列,最好每部有分析

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/07/14 23:29:51
用free pascal来编个程序求数串的原始排列,最好每部有分析
前N个自然数排成一串:X1,X2,X3…..Xn,先取出x1,将x2,x3移到数串尾,再取出x4,将x5,x6,x7移到数串尾,…….类推直至取完.取出的序列恰好是:1,2,3……n
要求输入N,求原来的数串的排列方式.
不要太多函数,看不懂
感谢回答的人,我天灵盖掀了,自己做出了,分享
var n,t,i,m,k,s:integer;
var a,b,c:array [1..n] of integer;
begin
readln(n); t:=0;
for i:=1 to n do
a[i]:=i;
repeat
inc(t);
a[1]:=b[t];
for i:= 2 to n do
a[i-1]:=a[i];
a[1]:=m; a[2]:=k;
for i:=3 to n do
a[i-2]:=a[i];
s:=0;
repeat
inc(s);
until a[s]=0;
a[s]:=m; a[s+1]:=k;
until t=n;
for i:=1 to n do
c[b[i]]:=i;
for i:=1 to n do
write(c[i],' ');
end.
楼主,真是服了你,问题都描述不清楚.原题是每次将取走数的后面两个数移到末尾,哪来的x7?!解决这个问题可以用双向链表,然后按取数的逆规则运作就行了.
program NumSort;
const
STEP = 2;
type
PRec = ^TRec;
TRec = record
data: Integer;
prev: PRec;
next: PRec;
end;
var
n, i: Integer;
head, tail, cur, p: PRec;
begin
Readln(n);
if n