求调(c++)

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

albertma @ 2024-10-13 16:57:18

#include<bits/stdc++.h>
using namespace std;
int n,q;
int m[8]={1,10,100,1000,10000,100000,1000000,10000000};
int a[1005]; 
int main(){
    cin>>n>>q;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    while(q--){
        int l,r;
        cin>>l>>r;
        int temp=-1;
        for(int i=1;i<=r;i++){
            int x=a[i]%m[l];
            if(x==r){
                temp=a[i];
                break;
            }
        }
        cout<<temp<<endl;
    }
    return 0;
}

by tsgaoyunxuan @ 2025-01-08 22:10:34

@albertma,您试下我的代码,亲,应该能过!

#include<bits/stdc++.h>
using namespace std;
int n,q,book[7000],len[7000],num[7000];
int main(){
    cin>>n>>q;
    for(int i=1;i<=n;i++){
        cin>>book[i];
    }
    for(int i=1;i<=q;i++){
        cin>>len[i]>>num[i];
        int tmp=pow(10,len[i]),min=10000001;
        for(int j=1;j<=n;j++){
            if(book[j]%tmp==num[i]&&book[j]<min){
                min=book[j];
            }
        }
        if(min!=10000001){
            cout<<min<<endl;
        }
        else {
            cout<<-1<<endl;
        }
    }
    return 0;
}

这个是我的代码,here you go


|