update
[archive.git] / Apkawa / Study / pascal / lab4 / lab4.pas
blobdbca67786f3785a1c74f46e6810c7e016d650d84
1 program lab4;
2 type
3 uelem_type = ^element_type;
4 element_type = record
5 a: integer;
6 n: integer;
7 next: uelem_type;
8 end;
10 function pow( a,b:real):real;
11 { функция возведения в степень (a^b) }
12 var t:real;
13 begin
14 t := abs(a);
15 if a < 0 then pow := (-1)*exp(b*ln(t))
16 else pow := exp(b*ln(t));
17 end;
20 function parse_polinom(str_line:string): uelem_type;
21 var
22 polinom, polinom_first: uelem_type;
23 i, p, code: integer;
24 begin
25 new(polinom_first);
26 polinom := polinom_first;
27 p:=1;
28 for i:=1 to ord( str_line[0] ) do
29 begin
30 if str_line[i] <> ' ' then
31 begin
32 with polinom^ do
33 begin
34 case p of
36 begin
37 val( str_line[i], a, code);
38 p := 2;
39 end;
41 begin
42 val( str_line[i], n, code);
43 new( next);
44 polinom := next;
45 p := 1;
46 end;
47 end;
48 end;
49 end;
50 end;
51 polinom^.next := nil;
52 parse_polinom := polinom_first;
54 end;
55 function calc_polinom( x: longint; polinom: uelem_type):longint;
56 var
57 res: longint;
58 begin
59 res := 0;
60 while True do
61 begin
62 with polinom^ do
63 begin
64 if next = nil then
65 break;
66 res := res +( a* round(pow(x,n) ));
68 writeln( a, ' ', n, ' ',res );
69 polinom := next
70 end;
71 end;
72 calc_polinom:= res;
73 end;
75 function main: integer;
76 const
77 IN_PATH = 'lab4.in';
78 OUT_PATH = 'lab4.out';
79 var
80 in_file: text;
81 out_file: text;
82 str_line: string;
83 begin
84 assign( in_file, IN_PATH);
85 reset( in_file);
86 readln( in_file, str_line);
87 close( in_file);
89 assign(out_file, OUT_PATH);
90 rewrite( out_file);
91 writeln(out_file, str_line);
92 writeln(out_file,'----');
93 writeln( out_file, calc_polinom( 69, parse_polinom( str_line ) ) );
94 close(out_file);
97 end;
99 begin
100 main;
101 end.