Блок схемы
27.12.2010, 21:25. Показов 702. Ответов 0
помогите пожалуйста в построении блок схем по коду (Pascal)
| Pascal | 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
| program sp;
uses crt;
type Stack = ^pStack;
pStack = record
el: real;
next: Stack;
end;
type Stackchar = ^pStackchar;
pStackchar = record
el: char;
next: Stackchar;
end;
var
top: Stack;
topTemp: STackchar;
i, x, k, z : integer;
c, ch : char;
str, strp: string;
op1, op2: real;
flag : boolean;
procedure Init(var top: Stack);
begin top := nil;
end;
procedure InitChar(var top: StackChar);
begin top := nil;
end;
procedure Push(el: real; var top: Stack);
var p: Stack;
begin
new(p);
p^.el := el;
p^.next := top;
top := p;
end;
procedure PushChar(el: char; var top: StackChar);
var p: StackChar;
begin
new(p);
p^.el := el;
p^.next := top;
top := p;
end;
procedure Pop(var el: real; var top: Stack);
var p: Stack;
begin
el := top^.el;
p := top;
top := top^.next;
dispose(p);
end;
procedure PopChar(var el: char; var top: StackChar);
var p: Stackchar;
begin
el := top^.el;
p := top;
top := top^.next;
dispose(p);
end;
begin
InitChar(topTemp);
flag := false;
Read(str);
z := 1;
for i := 1 to Length(str) do begin
Val(str[i], x, k);
if (k = 0) then
Insert(str[i], strp, z);
if (str[i] = '+') or (str[i] = '-') or (str[i] = '*') or (str[i] = '/') then
PushChar(str[i], topTemp);
if (str[i] = '(') then
PushChar(str[i], topTemp);
if (str[i] = ')') then begin
PopChar(c, topTemp);
while c <> '(' do begin
Insert(c, strp, z);
z := z + 1;
PopChar(c, topTemp);
if (c = '(') then
break;
end;
PopChar(c, topTemp);
if (c = '+') or (c = '-') or (c = '*') or (c = '/') then
Insert(c, strp, z)
else
PushChar(c, topTemp);
end;
z := z + 1;
end;
while topTemp <> nil do begin
PopChar(c, topTemp);
Insert(c, strp, z);
z := z + 1;
end;
Writeln(strp);
Readln;
Init(top);
for i := 1 to Length(str) do begin
Val(strp[i], x, k);
if (k = 0) then
Push(x, top);
if (str[i] = '+') then begin
Pop(op1, top);
Pop(op2, top);
Push(op1 + op2, top);
end;
if (strp[i] = '-') then begin
Pop(op1, top);
Pop(op2, top);
Push(op2 - op1, top);
end;
if (strp[i] = '*') then begin
Pop(op1, top);
Pop(op2, top);
Push(op1 * op2, top);
end;
if (strp[i] = '/') then begin
Pop(op1, top);
Pop(op2, top);
Push(op2 / op1, top);
end;
end;
Pop(op1, top);
Writeln(op1:5:5);
Readln;
end. |
|
№2
| Pascal | 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
| Program ochered;
Uses crt;
Type spd = ^Tspd;
Tspd = record
data:string;
next,last:spd;
end;
Var op:integer;
stek, stek1,stek2:spd;
st0,st1,st2:spd;
data:string;
procedure add(var sp,st:spd; data:string);
var temp:spd;
begin
new(temp);
temp^.data:=data;
temp^.next:=nil;
if sp = nil
then
begin
temp^.last:=nil;
sp:=temp;
st:=sp;
end
else
begin
temp^.last:=st;
st^.next:=temp;
st:=temp;
end;
end;
procedure view(sp:spd);
begin
if sp = nil
then
writeln('®зҐаҐ¤м Їгбв*');
while sp<>nil do
begin
write(sp^.data,' ');
sp:=sp^.next;
end;
end;
function proverka(sp:spd):boolean;
begin
if sp = nil
then
proverka:=false
else
proverka:=true;
end;
function del(var sp, st:spd):string;
var temp:spd;
begin
if sp = nil
then
begin
writeln('Error: ®зҐаҐ¤м Їгбв*');
readkey;
exit;
end;
del:=sp^.data;
temp:=sp;
sp:=sp^.next;
if sp = nil
then
st:=nil;
dispose(temp);
end;
procedure clear(var sp, st:spd);
var temp:spd;
begin clrscr;
while sp<>nil do
begin
temp:=sp;
sp:=sp^.next;
dispose(temp);
end;
st:=nil;
end;
function read_the_first_element(sp:spd):string;
var a:string;
begin
a:=sp^.data;
read_the_first_element:=a;
end;
function read_the_last_element(st:spd):string;
var a:string;
begin
a:=st^.data;
read_the_last_element:=a;
end;
procedure summa (sp:spd);
Var m:spd;
s,p:integer;
a,k:integer;
Begin
m:=sp;
s:=0;
p:=1;
while m <> nil do
begin
val (m^.data,a,k);
if k=0 then
s:=s+a;
p:=p*a;
m:=m^.next;
end;
write ('‘㬬* н«Ґ¬Ґ*в®ў ®зҐаҐ¤Ё а*ў**: ',s);
write ('Џа®Ё§ўҐ¤Ґ*ЁҐ нҐ¬Ґ*в®ў а*ў*®: ',p);
end;
procedure kratnost (sp:spd);
Var m:spd;
a,k,k1:integer;
Begin
m:=sp;
k1:=0;
while m <> nil do
begin
val (m^.data,a,k);
if k=0 then
begin
if (a mod 3 = 0) then begin inc(k1); end;
m:=m^.next;
end;
end;
writeln ('Љ®«ЁзҐбвў® н«Ґ¬Ґ*в®ў ®зҐаҐ¤Ё Єа*в*ле 3 а*ў*®: ',k1);
end;
begin
st0:=nil;
repeat
clrscr;
writeln;
writeln('1-„®Ў*ўЁвм н«Ґ¬Ґ*в');
writeln('2-“¤*«Ёвм н«Ґ¬Ґ*в');
writeln('3-Џ®Є*§*вм ®зҐаҐ¤м');
writeln('4-ЋзЁбвЁвм ®зҐаҐ¤м');
writeln('5-Џа®зЁв*вм ЇҐаўл© н«Ґ¬Ґ*в');
writeln('6-Џа®зЁв*вм Ї®б«Ґ¤*Ё© н«Ґ¬Ґ*в');
writeln('7-Ќ*宦¤Ґ*ЁҐ бг¬¬л Ё Їа®Ё§ўҐ¤Ґ*Ёп н«Ґ¬Ґ*в®ў ®зҐаҐ¤Ё');
writeln('8-Љ®«ЁзҐбвў® н«Ґ¬Ґ*в®ў ®зҐаҐ¤Ё Єа*в*лҐ 3');
writeln;
writeln('0-‚л室');
readln(op);
case op of
1:begin
clrscr;
write('‚ўҐ¤ЁвҐ §**зҐ*ЁҐ ¤®Ў®ў«пҐ¬®Ј® н«Ґ¬Ґ*в* ');
readln(data);
clrscr;
add(stek, st0, data);
writeln;
writeln('ќ«Ґ¬Ґ*в ¤®Ў*ў«Ґ*');
writeln;
writeln('‚*и* ®зҐаҐ¤м ');
writeln;
view(stek);
writeln;
writeln;
writeln('Ќ*¦¬ЁвҐ «оЎго Є«*ўЁиг ¤«п Їа®¤®«¦Ґ*Ёп');
readkey;
end;
2:begin
clrscr;
if proverka(stek) then
begin
writeln('н«Ґ¬Ґ*в ', del(stek, st0),' г¤*«Ґ*');
writeln;
writeln('‚*и* ®зҐаҐ¤м ');
writeln;
view(stek);
writeln;
writeln;
writeln('Ќ*¦¬ЁвҐ «оЎго Є«*ўЁиг ¤«п Їа®¤®«¦Ґ*Ёп');
readkey;
end else
begin
writeln('“¤*«Ґ*ЁҐ *Ґў®§¬®¦*®, ®зҐаҐ¤м Їгбв*');
writeln;
writeln;
writeln('Ќ*¦¬ЁвҐ «оЎго Є«*ўЁиг ¤«п Їа®¤®«¦Ґ*Ёп');
readkey;
end;
end;
3:begin
clrscr;
writeln;
writeln('‚*и* ®зҐаҐ¤м ');
writeln;
view(stek);
writeln;
writeln;
writeln('Ќ*¦¬ЁвҐ «оЎго Є«*ўЁиг ¤«п Їа®¤®«¦Ґ*Ёп');
readkey;
end;
4:begin
clear(stek, st0);
writeln('ЋзҐаҐ¤м ®зЁйҐ**');
writeln;
writeln;
writeln('Ќ*¦¬ЁвҐ «оЎго Є«*ўЁиг ¤«п Їа®¤®«¦*Ёп');
readkey;
end;
5:begin
clrscr;
writeln;
writeln('Џа®звс**л© ЇҐаўл© н«Ґ¬Ґ*в');
writeln;
writeln(read_the_first_element(stek));
writeln;
writeln('‚*и* ®зҐаҐ¤м ');
writeln;
view(stek);
writeln;
writeln;
writeln('Ќ*¦¬ЁвҐ «оЎго Є«*ўЁиг ¤«п Їа®¤®«¦*Ёп');
readkey;
end;
6:begin
clrscr;
writeln;
writeln('Џа®звс**л© Ї®б«Ґ¤*Ё© н«Ґ¬Ґ*в');
writeln;
writeln(read_the_last_element(st0));
writeln;
writeln('‚*и* ®зҐаҐ¤м ');
writeln;
view(stek);
writeln;
writeln;
writeln('Ќ*¦¬ЁвҐ «оЎго Є«*ўЁиг ¤«п Їа®¤®«¦*Ёп');
readkey;
end;
7:begin
summa (st0);
end;
8:begin
kratnost(stek);
end;
0:begin
halt(1);
end;
end;
until op=0;
summa(st0);
end. |
|
№3
| Pascal | 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
| Program skobki;
Uses crt;
Type stek=^pstek;
pstek=record
Data:char;
Next:stek;
end;
Var
a:string;
f:boolean;
i:integer;
procedure writeSt (x:char;Var h:stek);
Var a:stek;
Begin
New(a);
a^.data:=x;
if h=nil then begin
a^.next:=nil;
h:=a;
end
else
begin
a^.next:=h;
end;
h:=a;
end;
procedure DelSt (Var h:stek);
Var a:stek;
Begin
if (h<>nil) then begin
a:=h;
h:=h^.next;
dispose (a);
a:=h;
end
else
begin
Writeln ('udalenie nevozmojno');
end;
end;
procedure Sravnenie (Var a:string);
Var
Stack:stek;
Begin
Stack:=nil;
i:=1;
while (i<=Length(a)) and f do
begin
if (a[i]='(') or (a[i]='{') or (a[i]='[')
then
writeSt (a[i],Stack)
else
if (a[i]=')') or (a[i]='}') or (a[i]=']')
then
if (Stack <> nil) and (abs(Ord(a[i]) - Ord(Stack^.Data))<=2)
then
DelSt(Stack)
else
f:=False;
Inc(i);
end;
end;
Begin
Writeln('Vvedite skobki');
Readln(a);
f:=True;
if a<>' '
then
begin
Sravnenie(a);
if f
then
Writeln('Vse skobki rasstavleny verno')
else
Writeln('skobka ',a[i-1],'zakryta prejdevremenno');
end
else
Writeln('Stroka pusta');
Readln;
End. |
|
Добавлено через 3 часа 30 минут
ну же, плиз, не проходите мимо(((
0
|