-
Notifications
You must be signed in to change notification settings - Fork 0
/
aa.pas
59 lines (53 loc) · 899 Bytes
/
aa.pas
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
var a:array[1..100]of integer;
i,j,ans:integer;
procedure find(i,l,r:integer);
var o:integer;
begin
// write(l,' ',r);
// writeln;
o:=(l+r)div 2;
if r-l>1 then begin
if i>=a[o] then find(i,o,r);
if i<a[o] then find(i,l,o);
end;
if r-l<=1 then writeln(l);
end;
function part(l,r:integer):integer;
var i,j,k,q:integer;
begin
i:=l-1;
k:=a[r];
for j:=l to r-1 do
begin
if a[j]<k then begin
inc(i);
q:=a[j];
a[j]:=a[i];
a[i]:=q;
end;
end;
q:=a[i+1];
a[i+1]:=a[r];
a[r]:=q;
part:=i+1;
end;
procedure qs(l,r:integer);
var i:integer;
begin
if l<r then begin
i:=part(l,r);
qs(l,i-1);
qs(i+1,r);
end;
end;
begin
randomize;
for i:=1 to 100 do begin a[i]:=random(100); write(a[i],' '); end;
qs(1,100);
writeln;
i:=random(100);
writeln(i);
for j:=1 to 100 do write(a[j],' ');
writeln;
find(i,1,100);
end.