Barcelona_Messi @ 2018-02-14 19:57:55
using namespace std;
struct node
{ int lon,no;
}need[1001];
int main()
{ int n,q,book[1001],i,j,z,k,t,d,ji;
cin>>n>>q;
for(i=1;i<=n;i++)
cin>>book[i];
for(i=1;i<=q;i++)
cin>>need[i].lon>>need[i].no;
for(i=1;i<=n-1;i++)
for(j=1;j<=n-i;j++)
if(book[j]>book[j+1])
{ z=book[j];
book[j]=book[j+1];
book[j+1]=z;
}
for(i=1;i<=q;i++)
{ t=0;
d=1;
for(ji=1;ji<=need[i].lon;ji++)
d=d*10;
for(j=1;j<=n;j++)
{ k=book[j]%d;
if(k==need[i].no)
{ cout<<book[j]<<endl;book[j]=0;t=1;break;}
}
if(t==0)
cout<<"-1"<<endl;}
return 0;
}
by Barcelona_Messi @ 2018-02-14 20:00:23
using namespace std;
struct node
{ int lon,no;
}need[1001];
int main()
{ int n,q,book[1001],i,j,z,k,t,d,ji;
cin>>n>>q;
for(i=1;i<=n;i++)
cin>>book[i];
for(i=1;i<=q;i++)
cin>>need[i].lon>>need[i].no;
for(i=1;i<=n-1;i++)
for(j=1;j<=n-i;j++)
if(book[j]>book[j+1])
{ z=book[j];
book[j]=book[j+1];
book[j+1]=z;
}
for(i=1;i<=q;i++)
{ t=0;
d=1;
for(ji=1;ji<=need[i].lon;ji++)
d=d*10;
for(j=1;j<=n;j++)
{ k=book[j]%d;
if(k==need[i].no)
{ cout<<book[j]<<endl;book[j]=0;t=1;break;}
}
if(t==0)
cout<<"-1"<<endl;}
return 0;
}