-
Notifications
You must be signed in to change notification settings - Fork 0
/
circlecross.cpp
50 lines (45 loc) · 1.31 KB
/
circlecross.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
43
44
45
46
47
48
#include <iostream>
#include <algorithm>
//#include <cstdio>
#include <string>
#include <vector>
#include <array>
using namespace std;
bool is_duplicate(string order, int between, int first_loc, int second_loc) {
char letter = order[between];
for (int i=first_loc+1; i<second_loc; i++) {
if (order[i] == letter && i != between) {
return true;
}
}
return false;
}
int main () {
freopen("circlecross.in", "r", stdin);
freopen("circlecross.out", "w", stdout);
int counter = 0;
string order; cin >> order;
transform(order.begin(), order.end(), order.begin(), ::tolower);
for (int letter=97; letter<97+26; letter++) {
int first_loc = -1; int second_loc = -1;
bool done = false;
for (int loc=0; loc < 52 && !done; loc++) {
if (order[loc] == char(letter)) {
if (first_loc == -1) {
first_loc = loc;
} else {
second_loc = loc;
done = true;
}
}
}
for (int between=first_loc+1; between<second_loc; between++) {
if (is_duplicate(order, between, first_loc, second_loc)) {
;
} else {
counter++;
}
}
}
cout << counter / 2;
}