update
[archive.git] / Apkawa / Study / pascal / lab1_task_15 / old / task_15_mod_3.pas
blob24fbb519e1ef38a4a8fbc420605a4d62d79af935
1 program task_15_mod_2;
2 { use record type and use type file }
3 { tips for fpc - "fpc -mTP name_prog.pas" }
4 const
5 IN_FILE_PATH = 'task_15.in';
6 OUT_FILE_PATH = 'task_15_mod_3.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;
13 type
14 family = string[15];
15 phone = longint;
16 type_line = record
17 family: family;
18 phone: phone;
19 end;
21 var
22 in_file: file of type_line;
23 out_file: text;
24 i:integer;
25 in_lines: array [1 .. MAX_LINES] of type_line;
26 result_line: type_line;
28 procedure find_min_phone_and_first_letter_family(i: integer; var result_line: type_line );
29 begin
30 if i >1 then
31 begin
32 if in_lines[i].family[1] <= result_line.family[1] then
33 begin
34 if in_lines[i].phone < result_line.phone then
35 begin
36 result_line := in_lines[i];
37 end;
38 end;
39 end
40 else
41 result_line := in_lines[i];
42 end;
43 {END procedure find_min_phone_and_first_letter_family}
44 begin
45 assign( in_file, IN_FILE_PATH);
46 reset( in_file);
47 writeln( filesize( in_file) );
48 writeln( filepos( in_file) );
49 assign( out_file, OUT_FILE_PATH);
50 rewrite( out_file);
53 for i:=1 to MAX_LINES do
54 begin
55 {START read from in_file and write in out_file}
56 read( in_file, in_lines[i] );
57 writeln( out_file, in_lines[i].family, in_lines[i].phone);
58 {END}
59 find_min_phone_and_first_letter_family(i,result_line );
60 end;
62 close(in_file);
63 writeln(out_file);
64 writeln(out_file,'Result');
65 with result_line do
66 writeln( out_file, family, phone);
67 close( out_file);
68 end.