55022 - [NOIP2017]图书管理员(librarian)

解题思路

按照题目要求模拟。

代码实现

#include<bits/stdc++.h>
using namespace std;
const int mod[9] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000};
int b[1000];
int main() {
    int n, q;
    cin >> n >> q;
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    sort(b, b + n);
    while (q--) {
        int l, m;
        cin >> l >> m;
        int res = -1;
        for (int i = 0; i < n; ++i) {
            if (b[i] % mod[l] == m) {
                res = b[i];
                break;
            }
        }
        cout << res << '\n';
    }
    return 0;
}