|
沙发
楼主 |
发表于 2018-8-24 13:34:08
|
只看该作者
- #include<iostream>
- #include<algorithm>
- using namespace std;
- const int M=1010;
- int n,q,lens;
- string book[M],s;
- bool flag=0,flag2=0;
- bool cmp(string x,string y)
- {
- if(x.size()!=y.size())return x.size()<y.size();
- for(int i=0;i<x.size();i++)
- if(x[i]!=y[i])return x[i]<y[i];
- return x.size()<y.size();
- }
- int main()
- {
- cin>>n>>q;
- for(int i=1;i<=n;i++)
- cin>>book[i];
- sort(book+1,book+n+1,cmp);
- for(int i=1;i<=q;i++)
- {
- cin>>lens>>s;
- flag2=0;
- for(int j=1;j<=n;j++)
- {
- flag=0;
- for(int k=0;k<lens;k++)
- if(book[j][book[j].size()-lens+k]!=s[k])flag=1;
- if(flag)continue;
- cout<<book[j]<<endl;
- flag2=1;
- break;
- }
- if(!flag2)cout<<-1<<endl;
- }
- return 0;
- }
复制代码 |
|