-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditdist.cpp
More file actions
49 lines (41 loc) · 1.22 KB
/
Copy patheditdist.cpp
File metadata and controls
49 lines (41 loc) · 1.22 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
#include <bits/stdc++.h>
using namespace std;
ostream& operator<<(ostream& ostr, const vector<char>& v)
{
ostr << '|';
for (char c: v) ostr << (c == 0 ? ' ' : c);
ostr << '|';
return ostr;
}
int main(int argc, char*argv[])
{
const char* argv1 = argc > 2 ? argv[1] : "kitten";
const char* argv2 = argc > 2 ? argv[2] : "sitting";
string s1(argv1), s2(argv2);
int N = max(s1.size(), s2.size());
vector<char> v1(N*3);
vector<char> v2(N*3);
auto diff = [=](const vector<char> &l, const vector<char> &r)->int
{
cout << l << endl << r << endl << endl;
int c(0);
for (int i = 0; i < 3*N; ++i)
{
c += int(l[i] != r[i]);
}
return c;
};
copy(s1.begin(),s1.end(),v1.begin()+N);
copy(s2.begin(),s2.end(),v2.begin()+N);
diff(v1,v2);
int mindiff(INT_MAX);
if(1) for (int i = 0; i < 2*N; ++i)
{
v2.assign(3*N,0);
auto iv2 = v2.begin()+i;
copy(s2.begin(),s2.end(),iv2);
mindiff = min(mindiff,diff(v1,v2));
}
cout << s1 << " | " << s2 << ": " << mindiff << endl;
return 0;
}