Dreeick @ 2023-07-05 08:22:49
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;
}