40分求助

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

Flower_Bloom @ 2022-08-05 21:28:50

样例正确,神犇们快帮帮蒟蒻吧! (前四个点AC,5,6WA,7,8,9,10TLE)

    #include <bits/stdc++.h>
    using namespace std;
    int n, j, q, l, e, o = -1;
    int a[10000005], yu[10] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000,100000000,1000000000};
    int main() {
        cin >> n >> q;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        sort(a, a + n);
        j = q;
        while (j != 0) {
            j--;
            cin >> l >> n;
            o = -1;
            for (int i = 1; i <= n; i++) {
                e = a[i] % yu[l];
                if (e == n) {
                    o = a[i];
                    break;
                }
            }
            cout << o << endl;
        }
        system ("pause");
    }

by Flower_Bloom @ 2022-08-05 21:30:34

有人吗?


by wycha @ 2022-08-05 21:48:15

变量名重名了 @Mant1e


by Flower_Bloom @ 2022-08-05 21:49:40

哪一个?@wycha


by wycha @ 2022-08-05 21:50:42

有两个n,然后建议在竞赛中不要使用system ("pause");语句


by Flower_Bloom @ 2022-08-05 21:52:06

没有啊,都是在全局设置的一个n啊


by Flower_Bloom @ 2022-08-05 21:54:30

真的是大佬,竟然做过黑题!关注了关注了


by wycha @ 2022-08-05 21:55:02

后面cin >> l >> n;再次使用n会覆盖掉原来的n(数组长度),导致后面判断中for (int i = 1; i <= n; i++)(这里)n的值改变,进入死循环或者输出错误答案


by Flower_Bloom @ 2022-08-05 21:55:32

谢谢大佬!


by Flower_Bloom @ 2022-08-05 21:56:53

AC了大佬,谢谢!


|