1 条题解

  • 0
    @ 2025-4-12 22:03:05

    C :

    #include<stdio.h>
    #include<malloc.h>
    typedef struct student
    {
        int a;
        int b;
        struct student *next;
    } STU;
    int main()
    {
        int m,n;
        scanf("%d%d",&n,&m);
        int i,j,k,l;
        i=n;
        j=m;
        STU *q1,*q2,head1,head2,*p;
           q1=&head1;
           q2=&head2;
        while(i--)
        {
            p=(STU*)malloc(sizeof(STU));
            scanf("%d %d",&p->a,&p->b);
            q1->next=p;
            q1=q1->next;
        }
            while(j--)
        {
            p=(STU*)malloc(sizeof(STU));
            scanf("%d %d",&p->a,&p->b);
            q2->next=p;
            q2=q2->next;
        }
        q1->next=head2.next;
        STU *x,*y;
        for(x=head1.next; x!=NULL;x=x->next)
            for(y=x; y!=NULL;y=y->next)
            if(x->a>y->a)
        {
            int temp;
            temp=x->a;
            x->a=y->a;
            y->a=temp;
             temp=x->b;
            x->b=y->b;
            y->b=temp;
        }
        STU *g;
        g=head1.next;
        while(g!=NULL)
        {
            printf("%d ",g->a);
            printf("%d\n",g->b);
            g=g->next;
        }
        return 0;
    }
    
    

    C++ :

    #include <iostream>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    struct A
    {
        int num,score;
    }a[100000];
    int cmp(A p1,A p2)
    {
    
        if(p1.num<p2.num) return 1;
        else return 0;
    }
    int main()
    {
        int N,M,i,j,k;
        cin>>N>>M;
        for(i = 0,j = 0;i < N; i++,j++)
        cin>>a[j].num>>a[j].score;
        for(k = 0;k < M;k++,j++)
        cin>>a[j].num>>a[j].score;
        sort(a,a+N+M,cmp);
        for(i = 0;i < N + M; i++)
        cout<<a[i].num<<" "<<a[i].score<<endl;
       
        return 0;
    }
    
    
    • 1

    C语言程序设计教程(第三版)课后习题11.8

    信息

    ID
    2738
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者