forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorderlyclass.cpp
71 lines (55 loc) · 1.17 KB
/
orderlyclass.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2;
cin >> s1 >> s2;
string a1, a2;
for(auto i : s1) {
a1.push_back(i);
a1.push_back('.');
}
a1.pop_back();
for(auto i : s2) {
a2.push_back(i);
a2.push_back('.');
}
a2.pop_back();
vector<int> diff;
for(int i = 0; i < a1.size(); i++) {
if(a1[i] != a2[i]) {
diff.push_back(i);
}
}
if(diff.size() % 2 == 1) {
cout << 0 << endl;
return 0;
}
// Diff's size should be 2+
int center = (diff.front() + diff.back()) / 2;
// Iterate out from center to check if valid
int l = center;
int r = center;
while(true) {
if(a1[l] == a2[r] && a1[r] == a2[l]) {
l--;
r++;
}
else {
break;
}
if(l < 0 || r >= a1.size()) {
break;
}
}
l++;
r--;
if(l > diff.front() || r < diff.back()) {
cout << 0 << endl;
return 0;
}
int ways = 0;
for(int i = l; i <= diff.front(); i++) {
if(a1[i] != '.') ways++;
}
cout << ways << endl;
}