-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprob_409.cc
More file actions
82 lines (75 loc) · 1.28 KB
/
prob_409.cc
File metadata and controls
82 lines (75 loc) · 1.28 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
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include<sstream>
using namespace std;
vector<string> ks;
vector<pair<string,int> >strs;
string toLowCase(const string &line){
string nl=" ";
for(int p=0; p<line.length(); p++){
char a = line.at(p);
if(a>='A' && a <='Z'){
a = tolower(a);
nl+=a;
}
else if(!((a>='A' && a<='Z') ||(a>='a' && a<='z'))){
nl +=" ";
}
else {
nl+=a;
}
}
nl+=' ';
return nl;
}
int findK(const string &s){
int count =0;
for(int i =0; i<ks.size(); i++){
string k = ' '+ks[i]+' ';
int pos=0;
while((pos=s.find(k, pos))!=string::npos){
pos++;
count++;
}
}
return count;
}
void output(int t, int max){
cout << "Excuse Set #" << t << endl;
for(int i=0; i<strs.size(); i++){
if(strs[i].second ==max){
cout << strs[i].first <<endl;
}
}
cout << endl;
}
int main(){
int max = -1;
int Case =0;
int M, N;
while(cin>>M>>N){
for(int i=0; i<M; i++){
string key;
cin>>key;
ks.push_back(key);
}
cin.ignore();
for(int i=0; i<N; i++){
string line;
getline(cin, line);
string nl = toLowCase(line);
int nf = findK(nl);
if(nf>max){
max = nf;
}
strs.push_back(make_pair(line, nf));
}
Case++;
output(Case, max);
ks.clear();
strs.clear();
max = -1;
}
}