quzijie @ 2022-08-25 00:13:13
不知道为什么,判断的那一段运行了10次!找了好久没找出来.....
by quzijie @ 2022-08-25 00:13:43
#include<bits/stdc++.h>
using namespace std;
long long n,q,a[1000000],s,t,x,y,p,mi,e=1;
int main()
{
cin>>n>>q;
for(int i=1; i<=n; i++)
{
cin>>a[i];
}
sort(a+1,a+n+1);
mi=a[n];
for(int i=1; i<=q; i++)
{
cin>>s>>t;
for(int j=1; j<=n; j++)
{
p=a[j];
for(int b=1; b<=s; b++)
{
x=p%10;
y+=x*e;
p=p/10;
x=0;
e*=10;
}
if(mi>a[j]&&y==t) mi=a[j];
}
if(mi==a[n])
{
cout<<"-1"<<endl;
}
else cout<<mi<<endl;
y=0;
mi=a[n];
e=1;
}
return 0;
}
by SamHJD @ 2022-08-25 08:40:22
试试用字符串做,判断方便一点