-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind word.cpp
More file actions
136 lines (114 loc) · 1.76 KB
/
find word.cpp
File metadata and controls
136 lines (114 loc) · 1.76 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include"string"
#include<iostream>
#include<vector>
#include<string.h>
#include<typeinfo>
using namespace std;
int count_word(string s1, string s2)
{
int j = 0;
int s = 0;
int t;
if (s1.size()<s2.size())
s = 0;
else
{
for (int i = 0; i <= (s1.size() - s2.size()); i++)
{
t = i;
for (j = 0; j<s2.size();)
{
if (s1[t] == s2[j])
{
t++;
j++;
if (j == s2.size())
{
s++;
}
}
else
{
break;
}
}
}
}
// cout<<s<<endl;
return s;
}
int find_max(vector<int> v)
{
int t;
t=0;
for(int i=0;i<v.size();i++)
{
for(int j=0;j<v.size();j++)
{
if(v[i]<=v[j])
t=j;
}
}
return t;
}
int main(void)
{
vector<string> v1;
vector<string> v2;
vector<int> v3;
int M, N;
cout << "input M,N:";
cin >> M >> N;
cin.get();
while (M)
{
string s;
// cout<<"M="<<M<<endl;
getline(cin, s);
v1.push_back(s);
M--;
}
while (N)
{
string s;
// cout<<"N="<<N<<endl;
getline(cin, s);
v2.push_back(s);
N--;
}
// cout << "output v1 and v2:" << endl;
// for (int i = 0; i<v1.size(); i++)
// cout << v1[i] << " ";
// for (int i = 0; i<v2.size(); i++)
// cout << v2[i] << " ";
// cout << endl;
cout << "***********************************************" << endl;
// cout << count_word(v2[0], v1[0]) << endl;
// cout << v1.size() << " " << v2.size() << endl;
for (int i = 0; i<v2.size(); i++)
{
int s = 0;
for (int j = 0; j<v1.size(); j++)
{
// cout << "test" << endl;
int m;
m = count_word(v2[i], v1[j]);
s = s + m;
// cout << s << endl;
}
v3.push_back(s);
}
int max;
vector<int> v4;
max=find_max(v3);
for(int i=0;i<v3.size();i++)
{
if(v3[max]==v3[i])
v4.push_back(i);
}
for(int i=0;i<v4.size();i++)
{
cout<<v2[i]<<" ";
}
// cout<<v2[max];
}