-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdp.c
113 lines (106 loc) · 1.09 KB
/
rdp.c
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
/*
S->aBa|bCb
B->bB|c
C->cC|d
*/
#include<stdio.h>
#include<stdlib.h>
int i=0;
int B(char str[10])
{
switch(str[i])
{
case 'c':
{
i++;
return 1;
}
case 'b':
{
i++;
if(B(str) == 1)
return 1;
else
return 0;
}
default:
{
return 0;
}
}
}
int C(char str[10])
{
switch(str[i])
{
case 'd':
{
i++;
return 1;
}
case 'c':
{
i++;
if(C(str) == 1)
return 1;
else
return 0;
}
default:
{
return 0;
}
}
}
int S(char str[10])
{
int f2=0,f3=0;
switch(str[i])
{
case 'a':
{
i++;
f2=B(str);
if(f2!=0)
if(str[i] == 'a')
return 1;
else
return 0;
else
return 0;
}
case 'b':
{
i++;
f3=C(str);
if(f3!=0)
if(str[i] == 'b')
return 1;
else
return 0;
else
return 0;
}
default:
{
return 0;
}
}
}
int main()
{
int f1=0;
char str[30];
printf("\n enter the string:");
scanf("%s",str);
f1=S(str);
if(f1!=0)
{
printf("\n string is accepted..");
}
else
{
printf("\n string is rejected..");
}
return 0;
}