Files
python/TangDou/XiTi/1133.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

40 lines
1.1 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
int a[1001] = {0};
int main() {
//输入+输出重定向
freopen("../1133.txt", "r", stdin);
int n, q;
//n:图书馆里书的数量,q:读者的数量
cin >> n >> q;
//接下来的 n 行,每行包含一个正整数,代表图书馆里某本书的图书编码。
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
//接下来的 q 行,每行包含两个正整数,以一个空格分开,第一个正整数代表图书馆里读者的需求码的长度,第二个正整数代表读者的需求码
for (int i = 1; i <= q; ++i) {
int x, y;
cin >> x >> y;
//从a中去遍历查找如果是以x位10取模命中就是解
bool found = false;
for (int j = 1; j <= n; ++j) {
if (a[j] % int(pow(10, x)) == y) {
found = true;
cout << a[j] << endl;
break;
}
}
if (!found) cout << -1 << endl;
}
//关闭文件
fclose(stdin);
return 0;
}