-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSPEC-BAO-1.cpp
More file actions
80 lines (71 loc) · 2.08 KB
/
SPEC-BAO-1.cpp
File metadata and controls
80 lines (71 loc) · 2.08 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <bits/stdc++.h>
using namespace std;
// 2022-11-07 Marking (1 right, 0 wrong, * bug):
// 111111111 17/17
int alphabetI(char uppercaseLetter) {
return int(uppercaseLetter) - 65; // ASCII
}
int main() {
cout << "Hello World!\n";
string chrs;
cin >> chrs;
while(chrs.length() > 0) {
// Initialise vars
int lenChrs = chrs.length();
set<string> visitedWords;
bool hasPortals = true;
while (hasPortals) {
hasPortals = false;
// Check not infinite loop
if(visitedWords.count(chrs)!=0) {
hasPortals = true;
cout << "Indefinite\n";
break;
}
visitedWords.insert(chrs);
// Look for first portal and "teleport" it
for (int i = 0; i < lenChrs-1; i++) {
int firstLetterI = alphabetI(chrs[i]);
int secondLetterI = alphabetI(chrs[i+1]);
// cout << firstLetterI << " " << secondLetterI << "\n";
if(firstLetterI == 25-secondLetterI) {
// Portal
// Letter `i`s now around "portal" first letter
if(secondLetterI > firstLetterI) {
// Move surrounding chrs to end
if(i != 0) {
chrs.append(string(1,chrs[i-1]));
}
chrs.append(string(1,chrs[i+1]));
chrs.erase(i+1, 1);
if(i != 0) {
chrs.erase(i-1, 1);
}
hasPortals = true;
break;
} else {
// Move surrounding chrs to start
if(i != 0) {
// Move letter before
chrs.insert(0,string(1,chrs[i+1]));
chrs.insert(0,string(1,chrs[i]));
chrs.erase(i+3, 1);
chrs.erase(i+1, 1);
} else {
// No letter before
chrs.insert(0,string(1,chrs[i+1]));
chrs.erase(i+2, 1);
}
hasPortals = true;
break;
}
// cout << firstLetterI << " " << secondLetterI << "\n";
}
}
}
if (!hasPortals) { // Not indefinite
cout << chrs << "\n";
}
cin >> chrs;
}
}