using
System;
class
GFG {
static
readonly
int
ONE = 1;
static
readonly
int
TWO = 2;
static
char
[] StringFilter(
char
[] str)
{
int
state = ONE;
int
j = 0;
for
(
int
i = 0; i < str.Length; i++) {
if
(state == ONE && str[i] !=
'a'
&& str[i] !=
'b'
) {
str[j] = str[i];
j++;
}
if
(state == TWO && str[i] !=
'c'
) {
str[j] =
'a'
;
j++;
if
(str[i] !=
'a'
&& str[i] !=
'b'
) {
str[j] = str[i];
j++;
}
}
state = (str[i] ==
'a'
) ? TWO : ONE;
}
if
(state == TWO) {
str[j] =
'a'
;
j++;
}
return
String.Join(
""
, str)
.Substring(0, j)
.ToCharArray();
}
public
static
void
Main(String[] args)
{
char
[] str1 =
"ad"
.ToCharArray();
str1 = StringFilter(str1);
Console.Write(String.Join(
""
, str1) +
"\n"
);
char
[] str2 =
"acbac"
.ToCharArray();
str2 = StringFilter(str2);
Console.Write(String.Join(
""
, str2) +
"\n"
);
char
[] str3 =
"aaac"
.ToCharArray();
str3 = StringFilter(str3);
Console.Write(String.Join(
""
, str3) +
"\n"
);
char
[] str4 =
"react"
.ToCharArray();
str4 = StringFilter(str4);
Console.Write(String.Join(
""
, str4) +
"\n"
);
char
[] str5 =
"aa"
.ToCharArray();
str5 = StringFilter(str5);
Console.Write(String.Join(
""
, str5) +
"\n"
);
char
[] str6 =
"ababaac"
.ToCharArray();
str6 = StringFilter(str6);
Console.Write(String.Join(
""
, str6) +
"\n"
);
}
}