1 #include <set> 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <algorithm> 6 #include <vector> 7 using namespace std; 8 9 #define GI ({int _t; scanf("%d", &_t); _t;}) 10 #define FOR(i, a, b) for (int i=a; i<b; i++) 11 #define REP(i, a) FOR(i, 0, a) 12 template<class T> string toString(T n){ostringstream ost;ost<<n;ost.flush();return ost.str();} 13 int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;} 14 #define DBGV(_v) { REP(_i, _v.size()) { cout << _v[_i] << "\t";} cout << endl;} 15 bool isUpperCase(char c){return c>='A' && c<='Z';} 16 bool isLowerCase(char c){return c>='a' && c<='z';} 17 bool isLetter(char c){return c>='A' && c<='Z' || c>='a' && c<='z';} 18 bool isDigit(char c){return c>='0' && c<='9';} 19 char toLowerCase(char c){return (isUpperCase(c))?(c+32):c;} 20 char toUpperCase(char c){return (isLowerCase(c))?(c-32):c;} 21 22 23 int main() { 24 int key, line, kase = 0; 25 string tmp=""; 26 bool first = true; 27 while ( cin >> key && cin >> line) { 28 //if (first == false) printf("\n"); 29 first = false; 30 kase++; 31 set <string> keywords; 32 REP(i, key) { 33 string t; 34 cin >> t; 35 keywords.insert(t); 36 } 37 int maxmatch = -1; 38 vector <string> res; 39 cin >> tmp; 40 REP(i, line) { 41 string curline; 42 int match = 0; 43 getline(cin, curline); 44 if (tmp.size()>0) curline = tmp+curline; 45 tmp = ""; 46 curline += "\n"; 47 string word = ""; 48 REP(j, curline.size()) { 49 if (isLetter(curline[j])) { 50 word += toLowerCase(curline[j]); 51 } 52 else { 53 //cout << word << endl; 54 if (keywords.find(word) != keywords.end()) { 55 match++; 56 } 57 word = ""; 58 } 59 } 60 //cout << match << "\t" << curline ; 61 if (match > maxmatch) { 62 maxmatch = match; 63 res.clear(); 64 res.push_back(curline); 65 } 66 else if (match == maxmatch) { 67 res.push_back(curline); 68 } 69 } 70 printf("Excuse Set #%d\n", kase); 71 REP(i, res.size()) { 72 printf("%s", res[i].c_str()); 73 } 74 printf("\n"); 75 } 76 return 0; 77 }