求助,10pts

P3955 [NOIP2017 普及组] 图书管理员

ckjETO @ 2022-08-18 16:47:20

#include<bits/stdc++.h>
using namespace std;
int a[1005],m,n,b[1005],t[1005],s[1005];
int main(){
    memset(t,1,sizeof(t));
    cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=1;i<=m;i++){
        cin>>s[i]>>b[i];
        for(int j=1;j<=s[i];j++) {t[i]*=10;}
        for(int j=1;j<=n;j++)
            if(a[j]%t[i]==b[i]) {cout<<a[j]<<endl;break;}
            else if(j==n) {cout<<-1<<endl;break;}
    }
}

by ShanireZ @ 2022-08-18 16:52:27

memset(t,1,sizeof(t));

并不能让数组全部是1,这个操作是让每一位变1


by caramel_qwq @ 2022-08-18 16:56:42

@ckjETO memset改成手动for赋值


by caramel_qwq @ 2022-08-18 16:57:19

@ckjETO

for(int i=1;i<=n;i++){
   a[i]=1;
}

by C201529 @ 2022-08-18 16:58:03

@ckjETO

memset(t,1,sizeof(t));改为 fill(t,t+1002,1);


|