uva409 Excuses, Excuses!(字符串处理)
2015-04-04 16:51
393 查看
题目戳这里
题目大意:
给出一定量的关键词与一定量的句子,查找含有关键词量最多的句子,并输出,如果是多个句子,一并输出。
注意:
1.关键词在句子中出现必须是单词的形式,关键词是ab的时候在句子中出现的合法形式应该是:ab c 或ab,c等,abc则不算在内。
2.不区分大小写。
3.同一关键词在一个句子中多次出现只算一个。
思路:
注意到以上三点,直接模拟即可,可以运用string类里的find函数进行查找。
ac代码:
题目大意:
给出一定量的关键词与一定量的句子,查找含有关键词量最多的句子,并输出,如果是多个句子,一并输出。
注意:
1.关键词在句子中出现必须是单词的形式,关键词是ab的时候在句子中出现的合法形式应该是:ab c 或ab,c等,abc则不算在内。
2.不区分大小写。
3.同一关键词在一个句子中多次出现只算一个。
思路:
注意到以上三点,直接模拟即可,可以运用string类里的find函数进行查找。
ac代码:
[code]/* *Author : Flint_x *Created Time : 2015-04-04 15:36:49 *File name : uva409.cpp */ #include<iostream> #include<sstream> #include<fstream> #include<vector> #include<list> #include<deque> #include<queue> #include<stack> #include<map> #include<set> #include<bitset> #include<algorithm> #include<cstdio> #include<cstdlib> #include<cstring> #include<cctype> #include<cmath> #include<ctime> #include<iomanip> using namespace std; const double eps(1e-8); typedef long long lint; string key[25]; string ex[25]; string ex2[25]; int k,e; int find(int m){ int i, j, flag = 0; for (j = 1; j <= k; j++) if (ex[m].find(key[j]) != string::npos) { int a = ex[m].find(key[j]); if (ex[m][a - 1] < 97 || ex[m][a - 1] > 122) { int length = key[j].size(); if (ex[m][a + length] < 97 || ex[m][a + length] > 122) flag++; } } // cout << flag; return flag; } int main(){ //freopen("input.txt","r",stdin); int cnt = 0 ; while(cin >> k >> e){ cnt ++; int count[25]; int count2[25]; memset(count,0,sizeof(count)); memset(count2,0,sizeof(count2)); for(int i = 1 ; i <= k ; i++){ cin >> key[i]; } // getline(cin,ex[1]); getchar(); for(int i = 1 ; i <= e ; i++){ // char x = getchar(); // cout << x << endl; getline(cin,ex[i]); ex2[i] = ex[i]; // cout << ex[i] << endl; for(int j = 0 ; j < ex[i].length() ; j++){ if(ex[i][j] >= 'A' && ex[i][j] <= 'Z'){ ex[i][j] = ex[i][j] + 32; } } } for(int j = 1 ; j <= e ; j++){ count[j] = find(j); count2[j] = count[j]; } sort(count + 1, count + 1 + e); printf("Excuse Set #%d\n",cnt) ; for(int i = 1 ; i <= e ; i++){ if(count[e] == count2[i]){ // cout << count[e]; cout << ex2[i] << endl; } } cout << endl; } return 0; }
相关文章推荐
- uva 409 Excuses, Excuses!(字符串处理)
- UVa409_Excuses, Excuses!(小白书字符串专题)
- UVa409_Excuses, Excuses!(小白书字符串专题)
- uva 409 Excuses, Excuses!(字符串模拟)
- Excuses, Excuses! UVa409 字符串
- UVA 409 - Excuses, Excuses!(字符串)
- 字符串训练------UVA 409题目 Excuses, Excuses!
- HDU 1606(POJ 1598 UVA 409) Excuses, Excuses!(字符串匹配处理)
- Excuses, Excuses! - UVa 409 哈希字符串
- UVA 409 (暑假-字符串(2) -B - Excuses, Excuses!)
- UVA 409 Excuses, Excuses!
- uva-409 - Excuses, Excuses!
- UVa - 409 - Excuses, Excuses!
- Hdu Excuses, Excuses! 字符串处理 map应用
- uva 10361 Automatic Poetry(字符串处理)
- uva 401 Palindromes(字符串处理)
- uva 409 - Excuses, Excuses!
- uva 10878 Decode the tape(字符串处理)
- UVA 409 Excuses, Excuses!
- Uva 409 - Excuses, Excuses!