-input word -output word drow uses crt type achar bet bet record elem

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
{
-input:
>word.
-output:
>word.drow
}
uses crt;
type achar= ^bet;
bet=record
elem: char;
num: integer;
next: achar;
end;
var
start,wors,temp :achar;
input :string;
i,j,k,m,t :integer;
c:char;
begin
clrscr;
new(wors);
start:=wors;
i:=0;
read(c);
while c <> '.' do begin
//fill vector
inc(i);
new(temp);
temp^.next:=nil;
temp^.elem:=c;
temp^.num:=i;
wors^.next:=temp;
wors:=wors^.next;
read(c);
end;
t:=i;
inc(i);
while i>0 do begin //added char in end
wors:=start;
wors:=wors^.next;
while wors^.next<>nil do begin
if wors^.num=i then
c:=wors^.elem;
wors:=wors^.next;
end;
new(temp);
temp^.next:=nil;
temp^.elem:=c;
wors^.next:=temp;
wors:=wors^.next;
dec(i);
end;
wors:=start; //print
wors:=wors^.next;
while wors<>nil do begin
write(wors^.elem);
wors:=wors^.next;
end;
t:=t+(t-1); // length+half
while t>0 do begin //free memory
wors:=start;
for i:=1 to t do begin
wors:=wors^.next;
if i=t then Dispose(wors);
end;
dec(t);
end;
writeln;
readln;
end.