-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHayBales.cpp
More file actions
43 lines (32 loc) · 678 Bytes
/
HayBales.cpp
File metadata and controls
43 lines (32 loc) · 678 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
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdint>
using namespace std;
const vector<string> combinations = {
"PCC", "PPC", // -2 inversions
"PCP", "CPC"}; // -1 inversions
int main()
{
string input;
cin >> input;
string sorted(input);
sort(sorted.begin(), sorted.end());
uint64_t steps = 0;
while(input != sorted)
{
for(const auto combo : combinations)
{
auto index = input.find(combo);
if(index != string::npos)
{
sort((input.begin() + index), (input.begin() + index + 3));
steps++;
break; // in case a better inversion occurs from sort
}
}
}
cout << steps << endl;
return 0;
}