求助,60分,但我哪里错了啊

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

ChengZe @ 2018-10-25 22:53:58

include <bits/stdc++.h>

using namespace std; int main(){ long long n,q,a[1010]; cin>>n>>q; for(int i=1;i<=n;i++)scanf("%d",&a[i]); sort(a+1,a+1+n); for(int i=1;i<=q;i++){ long long x,y,z,flag=1; scanf("%d%d",&x,&y); z=pow(10,x); for(int j=1;j<=n;j++){ if(a[j]%z==y){ cout<<a[j]<<endl; flag=0; break; } } if(flag)cout<<-1<<endl; } return 0; }


by ChengZe @ 2018-10-25 22:55:13

include <bits/stdc++.h>

using namespace std; int main(){ long long n,q,a[1010]; cin>>n>>q; for(int i=1;i<=n;i++)scanf("%d",&a[i]); sort(a+1,a+1+n); for(int i=1;i<=q;i++){ long long x,y,z,flag=1; scanf("%d%d",&x,&y); z=pow(10,x); for(int j=1;j<=n;j++){ if(a[j]%z==y){ cout<<a[j]<<endl; flag=0; break; } } if(flag)cout<<-1<<endl; } return 0; }


by ChengZe @ 2018-10-25 22:59:18

#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,q,a[1010];
    cin>>n>>q;
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    for(int i=1;i<=q;i++){
        long long x,y,z,flag=1;
        scanf("%d%d",&x,&y);
        z=pow(10,x);
        for(int j=1;j<=n;j++){
            if(a[j]%z==y){
                cout<<a[j]<<endl;
                flag=0;
                break;
            }
        }
        if(flag)cout<<-1<<endl;
    }
    return 0;
} 

by March_H @ 2018-10-25 22:59:24

希望更丰富的展现?使用Markdown


|