using
System;
class
State
{
private
Tuple<
int
, State> Pair1;
private
Tuple<
int
, State> Pair2;
private
char
m_x;
public
static
State m_ptr;
public
State()
{
Pair1 =
new
Tuple<
int
, State>(0,
null
);
Pair2 =
new
Tuple<
int
, State>(0,
null
);
m_x =
' '
;
}
public
void
Initialize(Tuple<
int
, State> pair1,
Tuple<
int
, State> pair2,
char
x)
{
Pair1 = pair1;
Pair2 = pair2;
m_x = x;
}
public
static
void
Transition(
int
input)
{
if
(m_ptr.Pair1.Item1 == input)
{
m_ptr = m_ptr.Pair1.Item2;
}
else
{
m_ptr = m_ptr.Pair2.Item2;
}
}
public
static
void
Traverse(
string
str,
int
n)
{
for
(
int
i = 0; i < n; i++)
{
int
x = (
int
)Char.GetNumericValue(str[i]);
Transition(x);
}
}
public
static
void
Check()
{
if
(m_ptr.m_x ==
'f'
)
{
Console.WriteLine(
"String Accepted\n"
);
}
else
{
Console.WriteLine(
"String Rejected\n"
);
}
}
}
class
Program
{
static
void
IsAccepted(
string
str)
{
State one =
new
State();
State two =
new
State();
State three =
new
State();
one.Initialize(
new
Tuple<
int
, State>(0, two),
new
Tuple<
int
, State>(1, one),
'i'
);
two.Initialize(
new
Tuple<
int
, State>(0, two),
new
Tuple<
int
, State>(1, three),
'i'
);
three.Initialize(
new
Tuple<
int
, State>(0, two),
new
Tuple<
int
, State>(1, one),
'f'
);
int
length = str.Length;
State.m_ptr = one;
State.Traverse(str, length);
State.Check();
}
static
void
Main(
string
[] args)
{
string
str =
"00111101"
;
IsAccepted(str);
}
}