为什么40?

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

llljjjqqq @ 2017-11-17 19:24:45

#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    freopen("librarian.in","r",stdin);
    freopen("librarian.out","w",stdout);
    int n,q;
    scanf("%d %d",&n,&q);
     int a[n+5];
     for(int i=0;i<n;i++)
     {
    scanf("%d",&a[i]);
     }
     int b,c;
     for(int i=0;i<q;i++)
     {
         scanf("%d %d",&b,&c);
         int d=99999999;
         int t=1;
        for(int p=0;p<b;p++)
                 t=t*10;
         for(int j=0;j<n;j++)
         {
             if(a[j]%t==c&&d>c)
                 d=a[j];
         }
             if(d!=99999999)
                 printf("%d\n",d);
             else
                 printf("-1\n");
        }
        return 0;
}

by stray_233 @ 2017-11-17 19:36:41

int readlen[1005];
int s[10];
int i,j;
ifstream fin;
ofstream fout;
int main(){
    fin.open("librarian.in");
    fout.open("librarian.out");
    s[0]=1;
    for(i=1;i<10;i++)s[i]=s[i-1]*10;
    int n,q;
    fin>>n>>q;
    for(i=0;i<n;i++)fin>>books[i];
    for(i=0;i<q;i++)fin>>readlen[i]>>readers[i];
    for(i=0;i<q;i++){
        bool t=true;
        int min=10000000;
        for(j=0;j<n;j++){
            if(books[j]%s[readlen[i]]==readers[i]&&books[j]<min){
                min=books[j];
                t=false;
            }
        }
        if(t)fout<<-1<<endl;
        else fout<<min<<endl;
    }
    fin.close();
    fout.close();
    return 0;
}
我是这样的

|