编辑代码

#include <bits/stdc++.h>
using namespace std;
int n,m,stu,score;
typedef struct Node{
    int stu,score;
    Node *next;
}Node,*LinkList;
void init(LinkList &L){
    L=(Node *)malloc(sizeof(Node));
    L->next=nullptr;
}
void tailCreate(LinkList &a,LinkList &b){
    cin>>n>>m;
    Node *r1=a,*r2=b;
    Node *s;    
    for(int i=0;i<n;++i){
        cin>>stu>>score;
        s=(Node *)malloc(sizeof(Node));
        s->stu=stu;s->score=score;
        r1->next=s;
        r1=s;
    }
    r1->next=nullptr;
    for(int i=0;i<m;++i){
        cin>>stu>>score;
        s=(Node *)malloc(sizeof(Node));
        s->stu=stu;s->score=score;
        r2->next=s;
        r2=s;
    }
    r2->next=nullptr;
}
void print(LinkList L){
    int len=0;
    vector<pair<int,int> > v;
    Node *p=L->next;
    while(p!=nullptr){
        v.push_back(make_pair(p->stu,p->score));
        len++;
        p=p->next;
    }
    cout<<len<<'\n';
    for(int i=0;i<v.size();++i){
        cout<<v[i].first<<' '<<v[i].second<<'\n';
    }
}
int main() {
    LinkList a,b,c,t;
    init(a);
    init(b);
    init(c);
    tailCreate(a,b);
    int f=0;
    Node *ta=a,*tb=b,*tc=c;
    while(ta->next!=nullptr){
        ta=ta->next;
        tb=b;
        f=0;
        while(tb->next!=nullptr){
            tb=tb->next;
            if(ta->stu==tb->stu){
               f=1;
               break;
            }
        }
        if(f==0){
            tc->next=ta;
            tc=ta;
        }
    }
    tc->next=nullptr;
    print(c);
	return 0;
}