原本是一道很简单的题目么。
结果对于C++的IO函数,string的函数不熟悉,结果造成做了很长时间!!!!!
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cctype>
using namespace std;
int hasKey(vector<string> keys, string f){
for(int i=0; i<keys.size();i++){
if(f.compare(keys[i]) == 0)
return 1;
}
return 0;
}
int main(){
// ifstream fing("409.txt");
vector<string> keywords;
vector<string> excuses;
int kn, en;
const int max = 20;
int total = 1;
while(cin>>kn && cin>>en){
cin.ignore();
int count = 0;
int res[max] = {0};
string temp;
while(count < kn){
//getline(fing, temp);
getline(cin, temp);
keywords.insert(keywords.end(), temp);
// cout << temp << endl;
count++;
}
count = 0;
while(count < en){
//getline(fing, temp);
getline(cin, temp);
excuses.insert(excuses.end(), temp);
// cout << temp << endl;
count++;
}
int i = 0;
while(i < en){
string et = excuses[i];
int sz = et.size();
string tem;
for(int j=0; j<sz;j++){
if(isalpha(et[j])){
tem += tolower(et[j]);
}else{
if(hasKey(keywords, tem)==1)
res[i] = res[i]+1;
tem = "";
}
}
i++;
}
int sm = res[0];
for(i=0; i<en; i++){
if(res[i]>sm){
sm = res[i];
}
}
cout<<"Excuse Set #"<<total++<<endl;
for(i=0; i<en; i++){
//cout<<res[i]<<endl;
if(res[i] == sm)
cout<<excuses[i]<<endl;
}
cout<<endl;
keywords.clear();
excuses.clear();
}
// fing.close();
// system("pause");
return 0;
}