登 录
/* coder: ACboy date: 2010-3-6 result: AC description: UVa 409 Excuses, Excuses! */ #include <iostream> #include <algorithm> #include <string> #include <vector> #include <sstream> using namespace std; struct node { string str; int num; node(string a = "") : str(a), num() {} }; vector<node> excuess(30); vector<string> keyword(30); int binarySearch(string findStr, int k) { int begin = 0, end = k; int mid; while (begin <= end) { mid = (begin + end) / 2; if (keyword[mid] == findStr) { return 1; } else if (keyword[mid] > findStr) { end = mid - 1; } else { begin = mid + 1; } } return 0; } bool cmp(const node & a, const node & b) { return a.num > b.num; } int main() { int i, j; int k, e; int c = 0; #ifndef ONLINE_JUDGE freopen("409.txt", "r", stdin); #endif while (scanf("%d %d/n", &k, &e) != EOF) { for (i = 0; i < k; i++) { getline(cin, keyword[i]); } sort(keyword.begin(), keyword.begin() + k); for (i = 0; i < e; i++) { string str; getline(cin, str); excuess[i].str = str; int len = str.size(); for (j = 0; j < len; j++) { if (isalpha(str[j])) { str[j] = tolower(str[j]); } else { str[j] = ' '; } } istringstream in; in.str(str); int count = 0; while (!in.eof()) { string temp; in >> temp; count += binarySearch(temp, k); } excuess[i].num = count; } sort(excuess.begin(), excuess.begin() + e, cmp); int max = excuess[0].num; cout << "Excuse Set #" << ++c << endl; for (i = 0; i < e; i++) { if (excuess[i].num == max) { cout << excuess[i].str << endl; } else break; } cout << endl; } return 0; }
抱歉!评论已关闭.