-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSRM663.cpp
More file actions
29 lines (26 loc) · 726 Bytes
/
Copy pathSRM663.cpp
File metadata and controls
29 lines (26 loc) · 726 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
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
class ABBA {
public:
string canObtain(string initial, string target) {
bool lastLetterWasB;
while(target.size() >= initial.size()) {
if(target == initial) {
return "Possible";
}
if(target.substr(target.size() - 1) == "B") {
lastLetterWasB = true;
}
else {
lastLetterWasB = false;
}
target = target.substr(0, target.size()-1);
if(lastLetterWasB) {
reverse(target.begin(), target.end());
}
}
return "Impossible";
}
};