60分再次求助!!!
查看原帖
60分再次求助!!!
924648
ACcepted917楼主2024/7/15 16:57

题目链接P3955

代码:

#include<bits/stdc++.h>
using namespace std;
const int N=1e3+105;
typedef long long ll;
long long n,q,k,a[N],b,tmp,len;
bool flag;
int m[10]={1,10,100,1000,100000,1000000,10000000,100000000};
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>q;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	for(int i=1;i<=q;i++){
		cin>>len>>b;
		flag=0;
		for(int j=1;j<=n;j++){
			if(b==a[j]%m[len]){
				flag=1;
				cout<<a[j]<<'\n';
				break;
			}
		}
		if(!flag)cout<<-1<<'\n';
	}
	return 0;
}

求dalaodalao帮助,谢谢!!!

2024/7/15 16:57
加载中...