求助!!只对两个点!!!HELP!!!
查看原帖
求助!!只对两个点!!!HELP!!!
266774
wdzxghl楼主2020/7/24 10:53
#include<bits/stdc++.h>
using namespace std;
string s[2001];
int mark[2001];
int n,q;
bool cmp(string s,string t){
	return s.size()<t.size();
}
int main(){
	cin>>n>>q;
	for(int i=1;i<=n;i++)
	   cin>>s[i];
	sort(s+1,s+n+1,cmp);
	while(q--){
	    bool k=true;
		int len;
		string x;
		cin>>len>>x;
		//cout<<endl;
		for(int i=1;i<=n;i++){
			int len1=s[i].size();
			bool w=true;
			if(!mark[i]&&len1>=len){
			    string y;
			    for(int j=0;j<len;j++){
				y[j]=s[i][len1-len+j];
				//cout<<y[j];
				}
				bool w=false;
			    for(int j=0;j<len;j++){
			    	if(y[j]!=x[j]){
			    		w=true;
			    		break;
					}
				}
				if(!w){
					cout<<s[i]<<endl;
					mark[i]=1;
					k=false;
					break;
				}
			}
		}
		if(k)
		cout<<-1<<endl;
	}
	return 0;
}
2020/7/24 10:53
加载中...