Don't like ads? PRO users don't see any ads ;-)

# Homework v2.0

By: a guest on May 26th, 2012  |  syntax: None  |  size: 0.92 KB  |  hits: 96  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. program GGMU;
2. var
3.   k,n:longint;
4.   a:array [1..1003] of longint;
5.   f,g:text;
6. procedure Input();
7. var
8.   i:longint;
9. begin
10.   assign(f,'test.in');
11.   reset(f);
13.   for i:=1 to n do read(f,a[i]);
14.   close(f);
15. end;
16. procedure Output();
17. var
18.   i:longint;
19. begin
20.   assign(g,'test.out');
21.   rewrite(g);
22.   write(g,a[1]);
23.   for i:=2 to n do write(g,' ',a[i]);
24.   writeln(g);
25.   close(g);
26. end;
27. procedure Switch(var a,b:longint);
28. begin
29.   a:=a xor b;
30.   b:=a xor b;
31.   a:=a xor b;
32. end;
33. procedure Move(l,r:longint);
34. begin
35.   while (r>l) do
36.   begin
37.     Switch(a[r],a[r-1]);
38.     r:=r-1;
39.   end;
40. end;
41. procedure SetNumber(i:longint);
42. var
43.   j,pom:longint;
44. begin
45.   pom:=i;
46.   for j:=i+1 to n do
47.     if ((k>=j-i) and (a[j]>a[pom])) then pom:=j;
48.   Move(i,pom);
49.   k:=k-pom+i;
50. end;
51. procedure Solve();
52. var
53.   i:longint;
54. begin
55.   for i:=1 to n do SetNumber(i);
56. end;
57.
58. begin
59.   Input();
60.   Solve();
61.   Output();
62. end.