80分求大佬解答

P3955 [NOIP2017 普及组] 图书管理员

yukikaze @ 2018-01-02 16:05:17

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[10001],b[10001],c[10001],e[10001];
int main()
{
    //freopen("librarian.in","t",stdin);
    //freopen("librarian.out","w",stdout);
    long long n,q,i,j;
    cin>>n>>q;
    for(i=1;i<=n;i++)cin>>a[i];
    for(i=1;i<=q;i++)
    {
        cin>>b[i]>>c[i];
    }
    sort(a+1,a+n+1);
    for(i=1;i<=q;i++)
    {
        int s=1,x=0;
        for(j=1;j<=b[i];j++)
        s*=10;
        for(int k=1;k<=q;k++)
        if(a[k]%s==c[i]&&x==0)
        {
            e[i]=a[k];
            x++;
        }
    }
    for(i=1;i<=q;i++)
    {
        if(e[i]==0)e[i]=-1;
    }
    for(i=1;i<=q;i++)
    cout<<e[i]<<endl;
    //fclose(stdin);fclose(stdout);
    return 0;
}

|