Habseligkeit @ 2021-10-17 12:02:18
#include<bits/stdc++.h>
using namespace std;
const int INF=1000001;
long long k[11],b[1005],p[1005],len[1005],n,q;
int main(){
long long ans;
ans=INF;
cin>>n>>q;
for(int i=1;i<=n;i++)
cin>>b[i];
for(int i=1;i<=q;i++)
cin>>len[i]>>p[i];
k[1]=10;
for(int i=2;i<=9;i++)
k[i]=k[i-1]*10;
for(int i=1;i<=q;i++){
ans=INF;
for(int j=1;j<=n;j++){
int x=b[j]%k[len[i]];
if(x==p[i])ans=min(ans,b[j]);
}
if(ans==INF)cout<<-1<<endl;
else cout<<ans<<endl;
}
return 0;
}
by Habseligkeit @ 2021-10-17 12:05:07
我太蒟蒻了。。
by ZHUHK @ 2021-10-17 13:10:45
#include<bits/stdc++.h>
using namespace std;
const int N=1e6;
long long a[N];long long po[10];
bool cmp(long long a,long long b)
{
return a<b;
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
}
sort(a+1,a+1+n,cmp);
po[0]=1;
for(int i=1;i<=9;i++)
po[i]=po[i-1]*10;
for(int i=1;i<=m;i++)
{
long long len,number;
bool flag=false;
scanf("%lld%lld",&len,&number);
for(int i=1;i<=n;i++)
{
if(a[i]%po[len]==number)
{
flag=true;
printf("%lld\n",a[i]);
break;
}
}
if(flag==false) printf("%d\n",-1);
}
return 0;
}
by Habseligkeit @ 2021-12-18 21:17:05
谢谢您