c++,20分,大佬们帮忙看看哪里出问题了

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

Barcelona_Messi @ 2018-02-14 20:01:43

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
struct node
{ int lon,no;
}need[1001];
int main()
{ int n,q,book[1001],i,j,z,k,t,d,ji;
  cin>>n>>q;
  for(i=1;i<=n;i++)
   cin>>book[i];
  for(i=1;i<=q;i++)
   cin>>need[i].lon>>need[i].no;
  for(i=1;i<=n-1;i++)
   for(j=1;j<=n-i;j++)
    if(book[j]>book[j+1])
    { z=book[j];
      book[j]=book[j+1];
      book[j+1]=z;
    }
  for(i=1;i<=q;i++)
  { t=0;
    d=1;
    for(ji=1;ji<=need[i].lon;ji++)
     d=d*10;
    for(j=1;j<=n;j++)
     { k=book[j]%d;
        if(k==need[i].no) 
        { cout<<book[j]<<endl;book[j]=0;t=1;break;}  
     }
    if(t==0)
     cout<<"-1"<<endl;}
  return 0;
}

by 雪幽幽 @ 2018-07-22 18:00:15

我也二十分的c++


|