-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathMarbleNecklace.cpp
42 lines (38 loc) · 1.1 KB
/
MarbleNecklace.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
#include <string>
#include <vector>
#include <cstring>
#include <cmath>
#include <list>
#include <queue>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
using namespace std;
class MarbleNecklace {
public:
string normalize(string necklace) {
string res = necklace;
for (int i = 0; i < necklace.size(); ++i) {
string tmp = necklace.substr(i, necklace.size() - i + 1) +
necklace.substr(0, i);
if (tmp.compare(res) < 0) {
res = tmp;
}
}
reverse(necklace.begin(), necklace.end());
for (int i = 0; i < necklace.size(); ++i) {
string tmp = necklace.substr(i, necklace.size() - i + 1) +
necklace.substr(0, i);
if (tmp.compare(res) < 0) {
res = tmp;
}
}
return res;
}
};
int main() {
MarbleNecklace* necklace = new MarbleNecklace();
cout << necklace->normalize("SONBZELGFEQMSULZCNPJODOWPEWLHJFOEW") << endl;
return 0;
}