-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path409.cpp
More file actions
105 lines (87 loc) · 1.91 KB
/
409.cpp
File metadata and controls
105 lines (87 loc) · 1.91 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
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <sstream>
#include <cctype>
using namespace std;
int64_t k;
int64_t e;
vector<string> keywords;
vector<string> excuses;
vector<string> excusesTemp;
vector<string> output;
vector<int64_t> keywordsFoundCount;
void solve();
void readInput();
void processing();
void counting();
int main() {
int64_t setCount = 1;
while (cin >> k >> e) {
keywords.clear();
excuses.clear();
excusesTemp.clear();
output.clear();
keywordsFoundCount.clear();
cout << "Excuse Set #" << setCount++ << endl;
solve();
}
return 0;
}
void solve() {
readInput();
processing();
counting();
for (int64_t i = 0; i < output.size(); i++) {
cout << output.at(i) << endl;
}
cout << endl;
}
void readInput() {
string input;
for (int64_t i = 0; i < k; i++) {
cin >> input;
keywords.push_back(input);
}
for (int64_t i = 0; i < e + 1; i++) {
getline(cin, input);
excuses.push_back(input);
keywordsFoundCount.push_back(0);
}
excusesTemp = excuses;
}
void processing() {
for (int64_t i = 0; i < excusesTemp.size(); i++) {
for (int64_t j = 0; j < excusesTemp.at(i).size(); j++) {
if (ispunct(excusesTemp[i][j])) {
excusesTemp[i][j] = ' ';
}
excusesTemp[i][j] = tolower(excusesTemp[i][j]);
}
}
}
void counting() {
int64_t maxCount = 0;
for (int64_t i = 0; i < excusesTemp.size(); i++) {
stringstream excusesStream(excusesTemp.at(i));
string tempExcuse = "";
while (excusesStream >> tempExcuse) {
for (int64_t j = 0; j < keywords.size(); j++) {
if (tempExcuse == keywords.at(j)) {
keywordsFoundCount.at(i)++;
}
}
}
}
for (int64_t i = 0; i < keywordsFoundCount.size(); i++) {
if (keywordsFoundCount.at(i) > maxCount) {
maxCount = keywordsFoundCount.at(i);
}
}
for (int64_t i = 0; i < excuses.size(); i++) {
if (keywordsFoundCount.at(i) == maxCount) {
output.push_back(excuses.at(i));
}
}
}