哪错了?求助

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

Tokai_Fish @ 2020-10-17 21:01:26

#include<bits/stdc++.h>
using namespace std;
int c[1005]; 
int main(){
    int n,q,ans;
    cin>>n>>q;
    for(int i=1;i<=n;i++){
        cin>>c[i];
    }
    for(int i=1;i<=n;i++){
        int sum=1,a,b;
        cin>>a>>b;
        for(int i=1;i<=a;i++){
            sum*=10;
        }
        bool flag=true;
        ans=0x7fffffff;
        for(int i=1;i<=n;i++){
            if(c[i]%sum==b){
            flag=false;
            if(c[i]<ans) ans=c[i];
            } 
        }
        if(flag==false){
            cout<<ans<<endl;
        }
        else cout<<"-1"<<endl;
    }
    return 0;
} 

by Ritel @ 2020-10-17 21:32:23

@caojiahe 最外层循环应是1~q


by Tokai_Fish @ 2020-10-19 18:53:25

@Little_Down 谢谢大佬


|