40分求助 求看

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

guoyibo @ 2022-10-13 23:19:55

芝士记录

//芝士代码
#include<bits/stdc++.h> 
using namespace std;
int n,q; 
int reader[1001],book[1001],len[1001];
int main(){
    cin>>n>>q;
    for(int i=1;i<=n;i++){
        cin>>book[i];
    }
    for(int i=1;i<=q;i++){
        cin>>len[i]>>reader[i];
        int tmp = pow(10,len[i]);
        int minn = 1145141919;
        bool flag = false;
        for(int j=1;j<=n;j++){
            if(book[j]%tmp == reader[i] and book[j]<minn){
                minn = book[j];
                ;
                flag = true;
            }
        }
        if(flag == 1145141919){
            cout<<"-1"<<endl;
        }else{
            cout<<minn<<endl;
        }
    }
    return 0;
}

|