|
#include <iostream> |
|
#include <fstream> |
|
#include <vector> |
|
#include <string> |
|
#include <cstring> |
|
#include <cstdio> |
|
|
|
using namespace std; |
|
|
|
int main(int argc, char const *argv[]) |
|
{ |
|
ifstream gt_file, sub_file; |
|
gt_file.open(argv[1]); |
|
sub_file.open(argv[2]); |
|
string a((std::istreambuf_iterator<char>(gt_file)), |
|
std::istreambuf_iterator<char>()); |
|
string b((std::istreambuf_iterator<char>(sub_file)), |
|
std::istreambuf_iterator<char>()); |
|
const int n = a.size(); |
|
const int m = b.size(); |
|
vector<vector<int> > f(n+1, vector<int>(m+1, 0)); |
|
for (int i = 0; i <= n; ++i) f[i][0] = i; |
|
for (int j = 0; j <= m; ++j) f[0][j] = j; |
|
for (int i = 1; i <= n; ++i) { |
|
for (int j = 1; j <= m; ++j) { |
|
int w = (a[i - 1] == b[j - 1]) ? 0 : 1; |
|
f[i][j] = f[i - 1][j - 1] + w; |
|
f[i][j] = min(f[i][j], f[i][j - 1] + 1); |
|
f[i][j] = min(f[i][j], f[i - 1][j] + 1); |
|
} |
|
} |
|
int correct_count = 0; |
|
int add_count = 0; |
|
int sub_count = 0; |
|
int del_count = 0; |
|
int i = n, j = m; |
|
while (i > 0 && j > 0) { |
|
// cout << a.substr(0, i) << " " << b.substr(0, j) << " "; |
|
if (a[i - 1] == b[j - 1] && f[i][j] == f[i - 1][j - 1]) { |
|
// cout << "correct" << endl; |
|
--i; --j; |
|
++correct_count; |
|
} else if (a[i - 1] != b[j - 1] && f[i][j] == f[i - 1][j - 1] + 1) { |
|
// cout << "sub" << endl; |
|
--i; --j; |
|
++sub_count; |
|
} else if (f[i][j] == f[i - 1][j] + 1) { |
|
// cout << "del" << endl; |
|
--i; |
|
++del_count; |
|
} else { |
|
// cout << "add" << endl; |
|
--j; |
|
++add_count; |
|
} |
|
} |
|
if (i > 0) del_count += i; |
|
if (j > 0) add_count += j; |
|
cout << "File: " << argv[2] << endl; |
|
cout << "Edit distance " << f[n][m] << endl; |
|
cout << "# correct " << correct_count << endl; |
|
cout << "# add " << add_count << endl; |
|
cout << "# sub " << sub_count << endl; |
|
cout << "# del " << del_count << endl; |
|
cout << "Total score: " << |
|
correct_count - 5 * (add_count + sub_count + del_count) << endl; |
|
gt_file.close(); |
|
sub_file.close(); |
|
return 0; |
|
} |