判题结果经常变
查看原帖
判题结果经常变
470092
九歌扬灵楼主2021/11/28 11:45

判题结果老变,一会儿一个A四个UKE,一会儿俩A一个超时,俩UKE;又一会儿编译错误。求大佬帮助(|-|),感谢感谢感谢!!!

#include<iostream>
using namespace std;
struct listnode
{
    int val;
    listnode* next;
};
void insert(listnode* head,int a, int b,int c)
{
    listnode* p = head;
    listnode* q;
    while (p->val != a)
    {
        q = p;
        p = p->next;
    }
    listnode* newnode = new listnode;
    newnode->val = b;
    newnode->next = NULL;
    if (c == 1)
    {
        newnode->next = p->next;
        p->next = newnode;
    }
    if (c == 0)
    {
        newnode->next = p;
        q->next = newnode;
    }
}
void remove(listnode*head,int a)
{
    listnode* p = head;
    listnode* q;
    while (p->val != a && p->next != NULL)
    {
        q = p;
        p = p->next;
    }
    if(p->next!=NULL)
    {
        q->next = p->next;
        delete p;
    }
    if(p->next==NULL)
    {
        if (p->val == a)
        {
            q->next = NULL;
        delete p;  
        }
            
    }

}
int main()
{
    int n;
    cin >> n;
    listnode* head = new listnode;
    head->val = -1;
    listnode* first = new listnode;
    first->val = 1;
    first->next = NULL;
    head->next = first;
    int num, set;
    for (int i = 2;i <= n;i++)
    {
        cin >> num >> set;
        insert(head, num, i, set);
    }
    int n2;
    cin >> n2;
    int num2;
    for (int i = 0;i < n2;i++)
    {
        cin >> num2;
        remove(head, num2);
    }
    head = head->next;
    while (head != NULL)
    {
        cout << head->val;
        if (head->next != NULL)cout << " ";
        else cout << endl;
        head = head->next;
    }
        system("pause");
}
2021/11/28 11:45
加载中...