想用一下STL里面的set
肿么就老是WA呢???为什么呢?
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <cctype>
using namespace std;
///
#define INF 0xffffff7
#define MAXN 200
int K, E; //k means k keywords E means E words to be searched
vector<string> excuses; //借口单词数组
vector<string> lines; //单行每一句借口
vector<int> maxpos; //最大关键词借口下标
set<string> keyWords; //关键词集合
int maxnum;
int times[2000];
int main()
{
///
int i, j, th;
int cases = 1;
while (cin >> K >> E)
{
keyWords.clear();
maxnum = 0;
memset(times, 0, sizeof(times));
//读入关键字
for (i = 0; i < K; i++)
{
string temp;
cin >> temp;
keyWords.insert(temp);
}
// getchar();
cin.ignore(); //去掉输入流中的回车
//读入句子
lines.clear();
maxpos.clear();
for (i = 0; i < E; i++)
{
excuses.clear();
string line, temp;
getline(cin, line);
lines.push_back(line);
istringstream stream(line);
while(stream >> temp)
{
while ((temp.size() != 0) && (!( (islower(temp[temp.size() - 1])) || (isupper(temp[temp.size() - 1])) ) ) )
{
temp.erase(temp.end() - 1);
}
if (temp.size() != 0)
{
for (j = 0; j < temp.size(); j++)
{
if (isupper(temp[j]))
{
temp[j] -= 'A' - 'a';
}
}
excuses.push_back(temp);
}
}
int timess = 0;
vector<string>::iterator itor = excuses.begin();
for ( ; itor != excuses.end(); itor++)
{
timess += keyWords.count(*itor);
}
times[i] = timess;
if (timess > maxnum)
maxnum = timess;
}
for (i = 0; i < E; i++)
{
if (times[i] == maxnum)
maxpos.push_back(i);
}
cout << "Excuse Set #" << cases << endl;
vector<int>::iterator maxpositor = maxpos.begin();
for ( ;maxpositor != maxpos.end(); maxpositor++)
{
cout << lines[*maxpositor] << endl;
}
cout << endl;
cases++;
}
///
return 0;
}