李翰


私信TA

用户名:2018007

访问量:1725

签 名:

题解里面有错误请指正,谢谢各位师傅。

等  级
排  名 1257
经  验 2936
参赛次数 2
文章发表 14
年  龄 0
在职情况 学生
学  校
专  业 计科

  自我简介:

解题思路:暴力解决

注意事项:边界的处理

参考代码:

#include<stdio.h>

#include<stdlib.h>

typedef struct node{

    int data,n;

    struct node *next,*ptr;

}node;

node* creadlist(int n){

    node *head,*p,*q;

    head=(node *)malloc(sizeof(node));

    head->next=NULL,head->ptr=NULL;

    q=head;

    q->data=0,q->n=0;

    for(int i=0;i<n;i++){

        p=(node *)malloc(sizeof(node));

        scanf("%d%d",&p->data,&p->n);

        p->next=q->next;

        q->next=p;

        p->ptr=q;

        q=p;

    }

    return head;

 }

void opea(node *heada,node *headb,int n){

    node *p,*q;

    node *s;

    int delete_n;

    p=heada->next,q=headb->next;

    for(;p!=NULL;){

            q=headb->next;

            for(;q!=NULL;){

                if(p->data==q->data){

                    s=p->ptr;

                if(p->next==NULL)

                    s->next=p->next; 

                else {

                    p->next->ptr=s;s->next=p->next;

                    }

                n-=1;

            }

            q=q->next;

    }

            p=p->next;

}

    p=heada->next;

    printf("%d\n",n);

    for(int i=0;i<n;i++){

        printf("%d %d\n",p->data,p->n);

        p=p->next;

        }

}

int main () {

    int n,m;

    scanf("%d%d",&n,&m);

    node *heada,*headb;

    heada=creadlist(n);

    headb=creadlist(m);

    opea(heada,headb,n);

    return 0;


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区