include algorithm include utility include map include iostream include

 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <algorithm>
#include <utility>
#include <map>
#include <iostream>
#include <fstream>
#include <iostream>
#include <iterator>
#include <set>
#include <string>
#include <vector>
using namespace std;
class biagr {
public: double spellchecker(const set<string> &a,const set<string> &b) {
set<string> s;
set_intersection(a.begin(), a.end(), b.begin(), b.end(), inserter(s, s.begin()));
double ssize = s.size();
if (ssize == 0) {
return 0;
}
else {
set_union(a.begin(), a.end(), b.begin(), b.end(), inserter(s, s.begin()));
double res = ssize / s.size();
return res;
}
return 0;
}
};
int main(int argc, char *argv[])
{
ifstream f;
biagr b;
f.open("count_big.txt");
vector<pair<string, int>> s;
map<int, set<string>> mass;
int k = 0, l = 0;
double u = 0, y = 0, p = 0;
string str1, str2;
while(f >> str1 >> k) {
s.push_back(pair<string, int>(str1, k));
set<string> c;
int len1 = str1.length() - 1;
if (len1 > 2) {
for(int i = 0; i < len1; i++) {
c.emplace(str1.substr(i, 2));
}
}
else {
c.emplace(str1);
}
mass[l++] = c;
}
set<string> re, tokens, bg;
while(cin) {
cin >> str1;
set<string> bg;
int len2 = str1.length() - 1;
if (len2 > 2) {
for(int i = 0; i < len2; i++) {
bg.emplace(str1.substr(i, 2));
}
}
else {
bg.emplace(str1);
}
u = 0;
p = 0;
y = 0;
l = 0;
for (auto r : s) {
u = b.spellchecker(bg, mass[l++]);
if (u > y ||(u == y && p < r.second)) {
y = u;
str2 = r.first;
p = r.second;
}
}
if (cin) {
cout << str2 << endl;
}
}
f.close();
return 0;
}