-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathABCheck.cpp
More file actions
61 lines (46 loc) · 979 Bytes
/
ABCheck.cpp
File metadata and controls
61 lines (46 loc) · 979 Bytes
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
#include <iostream>
#include <string>
using namespace std;
bool CheckBackward(size_t found, string str){
int b = *str.begin();
if((found-4) <= *str.begin()) return true; // size_t range - 0 to 65535
return false;
}
bool CheckFurther(size_t found, string str){
int h = str.end() - str.begin();
if((found+4) < (str.end() - str.begin()))
return true;
return false;
}
bool CheckForB(size_t found,string str){
if(CheckFurther(found,str)){
if(str.at(found+4) == 'b' ){
return true;
}
}
if(CheckBackward(found,str)){
if(str.at(found-4) == 'b' ){
return true;
}
}
return false;
}
bool ABCheck(string str){
size_t found = str.find_first_of('a');
while(found != -1){
if(!CheckForB(found,str)){
found = str.find_first_of('a',found+1);
}else {
cout << "true" << endl;
return true;
}
}
cout << "false"<< endl;
return false;
}
void main(){
string str;
ABCheck("after badly");
ABCheck("Laura sobs");
ABCheck("kbaaaaatfd");
}