未知原因RE,求助悬关
  • 板块灌水区
  • 楼主ZJLmath
  • 当前回复6
  • 已保存回复6
  • 发布时间2023/6/22 18:05
  • 上次更新2023/11/3 13:20:49
查看原帖
未知原因RE,求助悬关
764672
ZJLmath楼主2023/6/22 18:05

刚输入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;
}

2023/6/22 18:05
加载中...