-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcfg_assignment.cpp
123 lines (103 loc) · 2.44 KB
/
cfg_assignment.cpp
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
#include<bits/stdc++.h>
using namespace std;
string m="A1B";
int main()
{
string s;
cin>>s;
bool a=false;
bool flag=false;
for(int i=0; i<s.size(); i++)
{
if(s[i]=='1')
a=true;
}
if(a)
{
cout<<"The input string is Accepted\n";
flag=true;
}
else cout<<"The input string is not Accepted\n"<<endl;
if(flag)
{
string sA,sB;
int i;
for(i=0; i<s.size(); i++)
{
if(s[0]=='1')
sA="e";
if(s[i] == '1' and i == 0)
{
sB=s.substr(1,s.size()-1);
break;
}
else if(s[i] == '1' and i != 0)
{
sA=s.substr(0,i);
sB=s.substr(i+1,((s.size()-i-1)));
break;
}
}
cout<<"Leftmost Derivative : \n";
cout<<"S-->A1B\n";
string tempA,tempB;
tempA.push_back('A');
for(int i=0;i<sA.size();i++)
{
if(sA=="e")break;
tempA="0"+tempA;
cout <<" -->"<< tempA<<"1B\n";
}
tempA.pop_back();
cout<<" -->" << tempA<<"1B\n";
tempB.push_back('B');
for(int i=0;i<sB.size();i++)
{
if(sB[i]=='0')
{
tempB.pop_back();
tempB+="0B";
cout<<" -->"<< tempA<<"1"<<tempB<<"\n";
}
else
{
tempB.pop_back();
tempB+="1B\n";
cout<<" -->"<< tempA<<"1"<<tempB;
}
}
tempB.pop_back();
tempB.pop_back();
cout<<" -->" << tempA<<"1"<<tempB;
cout<<"\n\nRightmost Derivative : ";
string t1, t2;
t2.push_back('B');
for(int i=0; i<sB.size(); i++)
{
if(sB[i]=='0')
{
t2.pop_back();
t2+="0B";
cout<< "A1"<<t2<<"-->";
}
else
{
t2.pop_back();
t2+="1B";
cout<< "A1"<<t2<<"-->";
}
}
t2.pop_back();
t1.push_back('A');
cout << t1<<"1"<<t2<<"-->";
for(int i=0; i<sA.size(); i++)
{
if(sA[i]=='e')
break;
t1="0"+t1;
cout << t1<<"1"<<t2<<"-->";
}
t1.pop_back();
cout <<t1<<"1"<<t2;
}
}