олимпиадная задача про сортировку времени

 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
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
n, temp: integer;
i,j: integer;
h, min, sec: array [1..100] of Integer;
f: TextFile;
begin
AssignFile(f, 'input.txt');
Reset(f);
ReadLn(f, n);
for i := 1 to n do
Read(f, h[i], min[i], sec[i]);
CloseFile(f);
for i := 1 to n - 1 do
for j := 1 to i do
if h[j] > h[j+1] then
begin
temp := h[j];
h[j] := h[j+1];
h[j+1] := temp;
temp := min[j];
min[j] := min[j+1];
min[j+1] := temp;
temp := sec[j];
sec[j] := sec[j+1];
sec[j+1] := temp;
end;
for i := 1 to n - 1 do
for j := 1 to i do
if (min[j] > min[j+1]) and (h[j] = h[j+1]) then
begin
temp := min[j];
min[j] := min[j+1];
min[j+1] := temp;
temp := sec[j];
sec[j] := sec[j+1];
sec[j+1] := temp;
end;
for i := 1 to n - 1 do
for j := 1 to i do
if (sec[j] > sec[j+1]) and (min[j] = min[j+1]) and (h[j] = h[j+1]) then
begin
temp := sec[j];
sec[j] := sec[j+1];
sec[j+1] := temp;
end;
AssignFile(f, 'output.txt');
Rewrite(f);
for i := 1 to n do
WriteLn(f, h[i], ' ', min[i], ' ', sec[i]);
CloseFile(f);
end.