-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathC.cpp
More file actions
88 lines (83 loc) · 1.74 KB
/
C.cpp
File metadata and controls
88 lines (83 loc) · 1.74 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
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
88
#include <iostream>
#include <map>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>
#include <cstring>
using namespace std;
const int prime = 31;
int dp[1001][1001];
int mx = 0;
int hashof(string str) {
int hash = 0;
for (int i = 0; i < str.size(); ++i) {
hash = (hash + (str[i]-31))*prime;
}
return hash;
}
int main (){
int t;
string s, name, str;
vector<int> mp[1001];
vector<string> names;
vector<string> answer;
cin >> t;
while(t--){
cin >> name; cin.ignore(100,'\n');
names.push_back(name);
while(getline(cin , s)){
if(s == "")continue;
str = "";
if (s == "***END***") break;
int k = 0, r = s.size()-1;
while (s[k++] == ' ');
while (s[r--] == ' ');
for (int i = k; i <= r; ++i){
if(str[str.size()-1] == ' ' && s[i] == ' ') continue;
str+=s[i];
}
mp[names.size()-1].push_back(hashof(str));
}
}
std::vector<int> vc;
while(getline(cin , s)){
if(s == "")continue;
str = "";
if (s == "***END***") break;
int k = 0, r = s.size()-1;
while (s[k++] == ' ');
while (s[r--] == ' ');
for (int i = k; i <= r; ++i){
if(str[str.size()-1] == ' ' && s[i] == ' ') continue;
str+=s[i];
}
vc.push_back(hashof(str));
}
for (int i = 0; i < names.size(); ++i) {
int _mx = 0;
for (int j = 0; j < mp[i].size(); ++j) {
for (int k = 0; k < vc.size() ; ++k){
int inc = 0;
while (j+inc < mp[i].size() && k+inc < vc.size() && mp[i][j+inc] == vc[k+inc])
inc++;
_mx = max(inc, _mx);
}
}
if (_mx > mx) {
mx = _mx;
answer.clear();
answer.push_back(names[i]);
}
else
if (_mx == mx) {
answer.push_back(names[i]);
}
}
cout << mx;
if (mx > 0) {
for (int i = 0; i < answer.size(); ++i)
cout << " " << answer[i];
}
cout << endl;
}