40分求助
查看原帖
40分求助
773371
Dreeick楼主2023/7/5 08:22

rt,代码如下

#include <iostream>
#include <set>
#include <string>

using namespace std;

set<string> s;
int n,q,QAQ;
string tmp;

bool is(string s1,const string &s2){
	if(s1.length() < s2.length()) return false;
	else if(s1.length() == s2.length()) return s1 == s2;
	else{
		s1.erase(0,s1.length() - s2.length());
		return s1 == s2;
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin >> n >> q;
	while(n--){
		cin >> tmp;
		s.insert(tmp);
	}
	while(q--){
		cin >> QAQ >> tmp;
		for(auto i : s){
			if(is(i,tmp)){
				cout << i << '\n';
				goto aim;
			}
		}
		cout << "-1\n";
		aim:
		continue;
	}

	return 0;
}
2023/7/5 08:22
加载中...