You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# 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 ;
}