[NOIP2017 普及组] 图书管理员
2024年12月25日小于 1 分钟
#include <bits/stdc++.h>
using namespace std;
int n, q;
int book[1005];
int ten[15]; // 预处理 10^i
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
ten[0] = 1;
for (int i = 1; i <= 8; i++)
ten[i] = ten[i - 1] * 10;
cin >> n >> q;
for (int i = 1; i <= n; i++)
cin >> book[i];
while (q--)
{
int len, num; // 需求码长度和需求码
cin >> len >> num;
int ans = -1;
for (int i = 1; i <= n; i++)
if (book[i] % ten[len] == num)
{
if (ans == -1 || book[i] < ans)
ans = book[i];
}
cout << ans << "\n";
}
return 0;
}