-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckAB.cpp
53 lines (49 loc) · 972 Bytes
/
CheckAB.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
#include <iostream>
using namespace std;
bool helper(char input[]){
if(input[0]=='\0')
return true;
if(input[0]=='a'){
if(input[1]=='a'){
return helper(input+1);
}
else if(input[1]=='b'){
return helper(input+1);
}
if(input[1]=='\0'){
return true;
}
else{
return false;
}
}
else if(input[0]=='b'){
if(input[1]=='b'&& input[2]=='a'){
return helper(input+2);
}
else if(input[1]=='b' && input[2]=='\0'){
return true;
}
else{
return false;
}
}
}
bool checkAB(char input[]) {
if(input[0]=='a'){
return helper(input+1);
}
else{
return false;
}
}
int main() {
char input[100];
bool ans;
cin >> input;
ans=checkAB(input);
if(ans)
cout<< "true" << endl;
else
cout<< "false" << endl;
}