Thinking
This question is very simple, cut off half an hour, is the code a bit ugly QAQ such a problem with food so long code, but - whines, I knocked my wayward code is fast haha.
Do not speak the idea, too simple, I used two helpers, in fact, should have the appropriate library functions can be used, but I'm too lazy to check, and besides I can not also check on the test, he was earning a living QAQ
Code
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<map>
using namespace std;
string p[1005],b[1005];
int x;
int cmp(string per,string book)
{
int lenp=per.length();
int lenb=book.length();
if(lenp>lenb)return 0;
for(int cosb=lenb-lenp,cosp=0;cosb<lenb;cosb++,cosp++)
{
if(book[cosb]!=per[cosp])
{
return 0;
}
}
return 1;
}
int turn(string s)
{
int ans=0,len=s.length();
for(int i=len-1,w=1;i>=0;i--,w*=10)
{
ans+=(s[i]-'0')*w;
}
return ans;
}
int main()
{
int n,q;
cin>>n>>q;
for(int i=1;i<=n;i++)
{
cin>>b[i];
}
for(int i=1;i<=q;i++)
{
cin>>x>>p[i];
}
for(int i=1;i<=q;i++)
{
int min=99999999;
for(int j=1;j<=n;j++)
{
if(cmp(p[i],b[j])&&turn(b[j])<min)
{
min=turn(b[j]);
}
}
if(min==99999999)
{
cout<<-1<<endl;
}
else
{
cout<<min<<endl;
}
}
return 0;
}