求助,只过了#1和#2

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

Little_Andyyu @ 2022-08-23 21:02:13


#include<bits/stdc++.h>
using namespace std;
int j,k,a[10086];
void paixu()
{
int A;
    for(A=1;A<j;A++) {
for(int nb=1;nb<=j;nb++) {
    if(a[A]>a[nb]) {
        int t=a[A];
        a[A]=a[nb];
        a[nb]=t;
}

}

}

}
int main()
{
    cin>>j>>k;
    int C9,q;
    for(C9=1;C9<=j;C9++) {
        cin>>a[C9]; 
}
paixu();
for(C9=1;C9<=k;C9++) {
    int l,u;
    int p=0;
    cin>>l>>u;
    int f=pow(10,l);
    for(q=1;q<=j;q++) {
        if((a[q]-u)%f==0) {
        p=1;
        cout<<a[q]<<endl;
        break;
}}
if(p==0){printf("-1\n");}
}
    return 0;
}

by KarmaticEnding @ 2022-08-23 21:15:43

#include<bits/stdc++.h>
using namespace std;
int book[1000],need,weishu;
int main(){
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=0;i<n;i++){
        scanf("%d",&book[i]);

    }
    sort(book,book+n);
    for(int i=0;i<q;i++){
        cin>>weishu>>need;bool flag=false;
        for(int j=0;j<n;j++){
            int m=pow(10,weishu);
            if((book[j]-need)%m==0){
                cout<<book[j]<<endl;
                flag=true;
                break;
            }
        }
        if(!flag) cout<<"-1"<<endl;
    }
}

这是正确代码,宁自己对照对照吧~~


by kl2237 @ 2022-08-23 21:23:39

你排序有问题,改成sort就过了


by kl2237 @ 2022-08-23 21:25:27

#include<bits/stdc++.h>
using namespace std;
int j,k,a[10086];
int main()
{
    cin>>j>>k;
    int C9,q;
    for(C9=1;C9<=j;C9++) {
        cin>>a[C9]; 
}
sort(a+1,a+1+j);
for(C9=1;C9<=k;C9++) {
    int l,u;
    int p=0;
    cin>>l>>u;
    int f=pow(10,l);
    for(q=1;q<=j;q++) {
        if((a[q]-u)%f==0) {
        p=1;
        cout<<a[q]<<endl;
        break;
}}
if(p==0){printf("-1\n");}
}
    return 0;
}

就这样


by dengchengzhuo @ 2022-08-23 21:26:54

az,是格式炸了还是码风...


by consider_hostoj @ 2022-08-28 16:46:45

#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int n,m,x,z,k,st,a[1005];
int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++)
      scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    for (int i=1;i<=m;i++)
      {
        scanf("%d%d",&x,&k);
        st=-1;z=1;
        while(x) x--,z*=10;
        for (int j=1;j<=n;j++)
          if (k==a[j]%z) 
            {
                st=a[j];
                break;
            }
        printf("%d\n",st);
      }
}

|