UVaOJ 409 - Excuses, Excuses!
2012-11-10 15:46
357 查看
AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume
1. Elementary Problem Solving :: String
Description
无论在公司,还在学校。
为迟早找借口的事常有发生。
你要做的就是,给你一些借口中常常含有的关键词。
找出含有关键词数最多的借口。
注意一下几点:
关键词以小写形式给出,但在借口中,不计大小写。
即使一个借口中有多个关键词相同,它们仍然计算在关键词数内。
关键词在借口中应该连续,且前后必须有“换行”、“空格”或者“非字母字符”。
Type
String
Analysis
将关键词们放在一个set中,
找出每个借口中的单词,判断是否为关键词即可。
Solution
1. Elementary Problem Solving :: String
Description
无论在公司,还在学校。
为迟早找借口的事常有发生。
你要做的就是,给你一些借口中常常含有的关键词。
找出含有关键词数最多的借口。
注意一下几点:
关键词以小写形式给出,但在借口中,不计大小写。
即使一个借口中有多个关键词相同,它们仍然计算在关键词数内。
关键词在借口中应该连续,且前后必须有“换行”、“空格”或者“非字母字符”。
Type
String
Analysis
将关键词们放在一个set中,
找出每个借口中的单词,判断是否为关键词即可。
Solution
// UVaOJ 409 // Excuses, Excuses! // by A Code Rabbit #include <algorithm> #include <cctype> #include <cstring> #include <iostream> #include <set> using namespace std; const int MAXN = 22; int k, e; string str; string excuses[MAXN]; int cnt[MAXN]; int main() { int cnt_case = 0; while (cin >> k >> e) { // Input and solve. cin.get(); set<string> keywords; for (int i = 0; i < k; i++) { getline(cin, str); keywords.insert(str); } memset(cnt, 0, sizeof(cnt)); int max_cnt = 0; for (int i = 0; i < e; i++) { getline(cin, excuses[i]); str = excuses[i]; string tmp; for (int j = 0; j < str.length(); j++) { if (!isalpha(str[j])) { if (keywords.count(tmp)) cnt[i]++; tmp = ""; } else { tmp += tolower(str[j]); } } max_cnt = max(max_cnt, cnt[i]); } // Output. cout << "Excuse Set #" << ++cnt_case << endl; for (int i = 0; i < e; i++) if (cnt[i] == max_cnt) cout << excuses[i] << endl; cout << endl; } return 0; }
相关文章推荐
- UVAOJ 409 ——Excuses, Excuses! 模拟
- 【UVaOJ 409】Excuses, Excuses!
- UVa - 409 - Excuses, Excuses!
- uva - 409 - Excuses, Excuses!
- UVa_409 - Excuses, Excuses!
- UVA 409 (暑假-字符串(2) -B - Excuses, Excuses!)
- Uva 409-Excuses, Excuses!(串)
- 409 - Excuses, Excuses!
- uva409 Excuses, Excuses!(字符串处理)
- UVA 409 Excuses, Excuses!
- UVA-409 Excuses, Excuses!
- UVA409 - Excuses, Excuses!
- Excuses, Excuses! - UVa 409 哈希字符串
- Uva 409-Excuses, Excuses!(串)
- UVa 409 Excuses, Excuses!
- uva-409 - Excuses, Excuses!
- Uva 409 - Excuses, Excuses!
- UVa 409 Excuses, Excuses! (字符串匹配)
- UVA 409-Excuses, Excuses!(模拟)
- 409-Excuses, Excuses!