3个WA,其他全RE。请大佬们指点

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

D_M_ @ 2021-10-05 11:09:44

#include <bits/stdc++.h>
using namespace std;
int weishu[10]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};
int n,q,a[1010],b[1010],d;
int main(){
    cin >> n >> q;
    for(int i=1;i<n;i++){
        cin >> a[i];
    }
    sort(a,a+n);
    for(int i=1;i<q;i++){
        cin >> b[i];
        if(a[i]%weishu[i] == b[i]){
            cout << a[i]%weishu[i];
        }else{
            cout << -1;
        }
    }
    return 0;
}

by Eason_AC @ 2021-10-05 11:18:10

看你用的 sort(a,a+n),建议你把 for 循环里面的 1 改成 0


by D_M_ @ 2021-10-05 11:19:11

@Eason_AC 还是不行


by wjj255 @ 2021-10-05 11:25:39

#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
int main()
{
    int n,q,a[1001],p[10000001],x,y,r;
    cin>>n>>q;
    for(int i=1;i<=n;i++){cin>>a[i];p[a[i]]=1;}
    sort(a+1,a+1+n);
    for(int i=1;i<=q;i++){
        cin>>x>>y;
        for(int j=1;j<=n;j++){
            r=0;
            int c=floor(pow(10.0,x)+0.5);
            //cout<<c<<endl;
            if(y==a[j]%c){cout<<a[j]<<endl;p[a[j]]=0;r=1;break;}
        }
        if(!r)cout<<-1<<endl;
    }
    return 0;
}

by fwx123456 @ 2021-10-05 11:25:45

有问题啊


by fwx123456 @ 2021-10-05 11:26:08

@B站滴魔墨


by D_M_ @ 2021-10-05 11:27:14

@fwx123456 啊?那怎么写,请求指点


by lion0514 @ 2021-10-05 11:29:26

@B站滴魔墨 你把一个数带进n自己看看


by fwx123456 @ 2021-10-05 11:29:40

其实你取模可以搞个函数


by fwx123456 @ 2021-10-05 11:30:37

而且i应该=0啊


by D_M_ @ 2021-10-05 11:32:45

@fwx123456 新代码:

#include <bits/stdc++.h>
using namespace std;
int weishu[10]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};
int n,q,a[1010],b[1010],c[1010],d;
int main(){
    cin >> n >> q;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a,a+1+n);
    for(int i=0;i<q;i++){
        cin >> b[i];
        cin >> c[i];
        if(a[i]%weishu[n] == c[i]){
            cout << a[i]%weishu[i];
        }else{
            cout << -1;
        }
    }
    return 0;
}

上一页 | 下一页