This repository was archived by the owner on Apr 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpression.PAS
More file actions
61 lines (58 loc) · 1.4 KB
/
Copy pathExpression.PAS
File metadata and controls
61 lines (58 loc) · 1.4 KB
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
uses crt;
var s:string;verdict:boolean;f,t:text;parri,parrs, parpi, parps,parvi,parvs,i:longint;
function init(s:string):boolean;
var verd:boolean;i:byte;
begin
verd:=true;
while verd and (i<length(s)) do begin
if s[i] in
['/','*','+','-','(','[','{','1','2','3','4','6','7','8','9','0','}',']',')']
then verd:=true else verd := false;
inc(i);
end;
init:=verd;
end;
function op(character:char):boolean;
var local:boolean;
begin
local:=true;
case character of
'/','*','+','-': local:= false;
end;
op:=local;
end;
function eq(n1,n2:integer):boolean;
begin
eq:=n1=n2;
end;
begin
clrscr;
readln(s);
parrs:=0;
parri:=0;
parps:=0;
parpi:=0;
parvs:=0;
parvi:=0;
for i:= 1 to length(s) do begin
case s[i] of
'(': inc(parri);
')': if parrs > parri then verdict:=false else inc(parrs);
'[': inc(parpi);
']': if parps > parpi then verdict:=false else inc(parps);
'{': inc(parvi);
'}': if parvs > parvi then verdict:=false else inc(parvs);
'/','*','+','-': if ((not op(s[i-1])) and (not op(s[i-1]))) then verdict:=false;
end;
end;
for i:= 1 to length(s) do begin
case s[i] of
')': if not op(s[i-1]) then verdict:=false;
']': if not op(s[i-1]) then verdict:=false;
end;
end;
writeln(parrs,parri,parps,parpi);
verdict:=init(s) and op(s[1]) and op(s[length(s)]) and (eq(parri,parrs)) and eq(parpi,parps) and eq(parvi,parvs);
if verdict = false then writeln('NU') else writeln ('DA');
readkey;
end.