difficultlong @ 2024-09-28 10:03:39
#include<bits/stdc++.h>
using namespace std;
int n,q;
int tb[1001],fh[1001][9],xbc[1001],xb[1001];
int main(){
scanf("%d%d",&n,&q);
for(int i=1;i<=n;i++){
scanf("%d",&tb[i]);
}
for(int i=1;i<=q;i++){
scanf("%d%d",&xbc[i],&xb[i]);
}
sort(tb+1,tb+n+1);
for(int i=1;i<=n;i++){
int a=tb[i];
int j=1;
while(a){
fh[i][j]=a%10;
a/=10;
j++;
}
}
bool flag;
for(int i=1;i<=q;i++){
int a=xb[i],m[9];
int j=1;
while(j<=xbc[i]){
m[j]=a/10;
a%=10;
j++;
}
for(int k=1;k<=n;k++){
int l=1;
flag=true;
while(l<=xbc[i]){
if(m[l]!=fh[k][l]){
flag=false;
break;
}
l++;
}
if(flag){
printf("%d",tb[i]);
break;
}
}
if(!flag){
printf("-1");
}
}
return 0;
}
by difficultlong @ 2024-09-28 19:16:58
@luogu_hezhenmin1 等一下再加注释
by luogu_hezhenmin1 @ 2024-09-28 19:27:49
@difficultlong 我也不知道怎么改了
by difficultlong @ 2024-09-28 20:57:29
@luogu_hezhenmin1 好的,感谢,已关注