top1编程
← 返回题目
题解

【基础】图书管理员(librarian)

1 条题解

  • 0
    @ 2026-7-29 0:15:41
    #include<iostream>
    #include<cmath>
    using namespace std;
    int n,q,book[6666],len[6666],num[6666];
    
    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]>>num[i];
            int tmp = pow(10,len[i]),min = 10000001;
            for(int j=1; j<=n; j++) if(book[j] % tmp == num[i] && book[j] < min) min = book[j];
            if(min != 10000001) cout<<min<<endl;
            else cout<<-1<<endl; 
        }
        return 0;
    }
    
    • 1