more scripts file
[archive.git] / Apkawa / Study / pascal / lab1_task_15 / old / task_15_mod_2.pas
blob1fde0d30b450b27240b59a5153224319d9a1f68d
1 program task_15_mod_2;
2 { use string array and use procedure }
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_2.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 result_line_type = string[MAX_LENGTH_LINE];
15 in_lines_type = array [1..MAX_LINES] of string[MAX_LENGTH_LINE];
16 var
17 in_file, out_file: text;
18 i:integer;
19 in_lines: in_lines_type;
20 result_line: result_line_type;
22 procedure find_min_phone_and_first_letter_family( i: integer; var result_line: result_line_type );
23 var
24 t: integer;
25 begin
26 if i > 1 then
27 begin
28 if in_lines[i,START_FAMILY] <= result_line[START_FAMILY] then
29 begin
30 for t:=START_PHONE to END_PHONE do
31 begin
32 if in_lines[i,t] <> result_line[t] then
33 begin
34 if in_lines[i,t] < result_line[t] then
35 begin
36 result_line := in_lines[i];
37 end;
38 break;
39 end;
40 end;
41 end;
42 end
43 else
44 result_line := in_lines[i];
45 end;
46 {END procedure find_min_phone_and_first_letter_family}
47 begin
48 assign( in_file, IN_FILE_PATH);
49 reset( in_file);
50 assign( out_file, OUT_FILE_PATH);
51 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 readln( in_file, in_lines[i]);
57 writeln( out_file, in_lines[i]);
58 {END}
59 find_min_phone_and_first_letter_family( i, result_line );
61 end;
62 close(in_file);
63 writeln(out_file);
64 writeln(out_file,'Result');
65 writeln(out_file,result_line);
66 close( out_file);
67 end.