题目戳这里
题目大意:
给出一定量的关键词与一定量的句子,查找含有关键词量最多的句子,并输出,如果是多个句子,一并输出。
注意:
1.关键词在句子中出现必须是单词的形式,关键词是ab的时候在句子中出现的合法形式应该是:ab c 或ab,c等,abc则不算在内。
2.不区分大小写。
3.同一关键词在一个句子中多次出现只算一个。
思路:
注意到以上三点,直接模拟即可,可以运用string类里的find函数进行查找。
ac代码:
/*
*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;
}
&spm=1001.2101.3001.5002&articleId=44873973&d=1&t=3&u=ba9eb81e73a44319ae8a04bccb5f4e4e)
2968

被折叠的 条评论
为什么被折叠?



