kun

秋风拂过发梢  •  11个月前


include

include

include

using namespace std;

int main() {

int n, q;
cin >> n >> q;  // 输入图书数量和读者数量

vector<int> books(n);
for (int i = 0; i < n; i++) {
    cin >> books[i];  // 输入图书编码
}

for (int i = 0; i < q; i++) {
    int length, demand;
    cin >> length >> demand;  // 输入需求码的长度和需求码

    int min_book_code = -1;
    for (int j = 0; j < n; j++) {
        string book_code_str = to_string(books[j]);  // 将图书编码转换为字符串
        string demand_str = to_string(demand);  // 将需求码转换为字符串

        if (book_code_str.length() >= length && book_code_str.substr(book_code_str.length() - length) == demand_str) {
            if (min_book_code == -1 || books[j] < min_book_code) {
                min_book_code = books[j];
            }
        }
    }

    cout << min_book_code << endl;
}

return 0;

}


评论:

请先登录,才能进行评论