刚输入K,E就返回3221225477
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int K,E;
string key[25];
struct Node{
string str;
int cnt;
int pos;
};
Node a[25];
bool search(string str){
for(int j=1;j<=K;j++){
if(key[j]==str){
return true;
}
}
return false;
}
void solve(int x){
string current=a[x].str;
string s="";
for(int j=0;j<current.length();j++){
if(current[j]==' '){
if(search(s)){
a[x].cnt++;
}
s="";
}else{
s+=current[j];
}
}
return;
}
bool cmp(Node X,Node Y){
return X.cnt>Y.cnt||(X.cnt==Y.cnt&&X.pos<Y.pos);
}
int main(){
int T=1;
while(scanf("%d %d",&K,&E)!=EOF){
for(int j=1;j<=25;j++){ // 清空数据
a[j].cnt=0;
a[j].str="";
}
string temp;
for(int j=1;j<=K;j++){
cin>>temp;
key[j]=temp;
}
for(int j=1;j<=E;j++){
getline(cin,a[j].str);
a[j].pos=j;
solve(j);
}
sort(a+1,a+E+1,cmp);
cout<<"Excuse Set #"<<T++<<endl;
for(int j=1;j<=E;j++){
if(a[j].cnt==a[1].cnt){
cout<<a[j].str<<endl;
}
}
}
return 0;
}