blob: bc6b1268455595b2f38fc6bd051d28a4836dcef9 (
plain)
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
|
clear;
clc;
disp("Unsolved example 3");
function[l]=strlen(x)
i=1;
l=0;
[j,k]=size(x)
for i=1:k
l=l+length(x(i));
end
endfunction
function[]=str(st)
stack=struct('a',0,'top',0);
st=string(st);
l=1;
l1=strlen(st);
symb=st(l);
valid=1;
while(l<l1)
while(symb~='C')
if(stack.top==0)
stack.a=st(l);
stack.top=stack.top+1;
else
stack.a=[stack.a(:,:) st(l)];
stack.top=stack.top+1;
end
l=l+1;
symb=st(l);
end
i=st(l+1);
if(stack.top==0)
valid=0;
break;
else
symb1=stack.a(stack.top);
stack.top=stack.top-1;
if(i~=symb1)
valid=0;
break;
end
end
l=l+1;
end
if(stack.top~=0)
valid=0;
end
if(valid==0)
disp("Not of the given format");
else
disp("String Of the Given Format");
end
endfunction
//Calling Routine:
st=['A' 'A' 'B' 'A' 'C' 'A' 'B' 'A' 'A']
str(st)
st=['A' 'A' 'B' 'A' 'C' 'A' 'B' 'A' ]
str(st)
|