Expectation @ 2022-05-29 14:54:15
字符串做法,调了好几天
已经有些面目全非
#include<iostream>
#include<cstdio>
using namespace std;
string book[1005];
int main()
{
int n,q,s,flagg=1;;
string smallest="99999999999";
string temp,a,b;
cin>>n>>q;
for (int i=1;i<=n;i++)
{
cin>>book[i];
}
for (int i=1;i<=q;i++)
{
cin>>s>>temp;
smallest="99999999999";
for (int j=1;j<=n;j++)
{
a=book[j];
b=book[j].erase(0,book[j].size()-s);
if (b==temp)
{
if (smallest.size()>a.size())
{
smallest=a;
flagg=1;
book[j]=a;
continue;
}
else if(smallest.size()==a.size() && smallest>a)
{
smallest=a;
flagg=1;
book[j]=a;
continue;
}
cout<<smallest<<endl;
flagg=1;
book[j]=a;
break;
}
else
{
cout<<"-1"<<endl;
flagg=1;
book[j]=a;
break;
}
}
}
return 0;
}