update
[archive.git] / Apkawa / Study / pascal / lab1_task_15 / task15_5.pas
blobc4565ee2df84eab4540ea94659c8dd91865fa478
1 program task_15_mod_5;
2 { use linear structure }
3 { tips for fpc - "fpc -mTP name_prog.pas" }
4 const
5 IN_FILE_PATH = 'task_15.in';
6 OUT_FILE_PATH = 'task15_5.out';
7 MAX_LENGTH_LINE = 24;
8 MAX_LINES = 10;
9 START_FAMILY = 1;
10 END_FAMILY = 15;
11 START_PHONE = 16;
12 END_PHONE = MAX_LENGTH_LINE;
14 procedure main( in_path, out_path: string);
15 type
16 uline_type = ^type_line ;
17 type_line = record
18 family: string[15];
19 phone: longint;
20 next_line : uline_type;
21 end;
23 var
24 in_file, out_file: text;
25 i:integer;
26 uline_cur, uline_next: uline_type;
27 family_line, phone_line: uline_type;
28 begin
29 assign( in_file, in_path);
30 reset( in_file);
32 assign( out_file, out_path);
33 rewrite( out_file);
35 new( uline_cur );
36 for i:=1 to MAX_LINES do
37 begin
38 with uline_cur^ do
39 begin
40 readln( in_file, family, phone );
41 writeln( family, phone);
42 new( uline_next);
43 next_line := uline_next;
45 writeln( out_file, family, phone);
46 {find min family and phone}
48 if i > 1 then
49 begin
50 if family_line^.family > family then
51 family_line := uline_cur;
52 if phone_line^.phone > phone then
53 phone_line := uline_cur;
54 end
55 else
56 begin
57 family_line := uline_cur;
58 phone_line := uline_cur;
59 end;
60 end;
61 uline_cur := uline_next;
62 end;
64 writeln(out_file);
65 writeln(out_file,'Result');
66 writeln( out_file, 'min family');
67 with family_line^ do
68 writeln( out_file, family,phone);
69 writeln( out_file, 'min phone');
70 with phone_line^ do
71 writeln( out_file, family,phone);
72 close( out_file );
73 close( in_file );
74 end;
75 begin
76 main( IN_FILE_PATH, OUT_FILE_PATH);
77 end.