20分,看不见输入无法Debug,请求帮助。
查看原帖
20分,看不见输入无法Debug,请求帮助。
386393
QS0x01楼主2020/10/1 12:45

请求各位有空帮忙捉虫,不知道哪里的逻辑有问题。 没爆内存也没超时的“半蛮力”办法。 自己随手编了几个数据喂进去吐出来都是正常的呀。

#include <bits/stdc++.h>
using namespace std;

struct box
{
    int i, j;
    long long k;
    box *next;
};

void operator1(box *&r)
{
    int i, j, k;
    cin >> i >> j >> k;

    box *p = new box[1];
    p->next = r;
    r = p;

    r->i = i;
    r->j = j;
    r->k = k;
}

void operator2(box *r)
{
    int i, j;
    cin >> i >> j;

    box *q = r;

    while (q->next != NULL && q->i != i && q->j != j)
    {
        q = q->next;
    }

    cout << q->k << endl;
}

int main()
{
    int n, q, o;

    cin >> n >> q;

    box *r = new box[1];
    r->next = NULL;

    for (int f = 0; f < q; f++)
    {
        cin >> o;

        if (o == 1)
        {
            operator1(r);
        }
        if (o == 2)
        {
            operator2(r);
        }
    }

    return 0;
}


2020/10/1 12:45
加载中...