1 条题解

  • 0
    @ 2025-4-7 21:19:29

    C :

    #include<stdio.h>
    #include<stdlib.h>
    struct aaa
    {
     int xx;
     struct aaa *next;
    };
    int main()
    {
      struct aaa *creat(struct aaa *head1,int N);
      void print(struct aaa *head1);
      struct aaa *link(struct aaa *head1,struct aaa *head2);
      struct aaa *head1,*head2;
      int N,M;
      head1 = head2 = NULL;
      scanf("%d",&N);
      head1=creat(head1,N);
      scanf("%d", &M);
      head2=creat(head2,M);
      head1 = link(head1,head2);
      print(head1);
      return 0;
    }
    struct aaa *creat(struct aaa *head1,int N)
    {
       struct aaa *p1,*p2;
       while (N--)
       {
       	p1 = (struct aaa *)malloc(sizeof(struct aaa));
       	scanf("%d", &p1 -> xx);
       	p1 -> next = NULL;
       	if (head1 == NULL)
       	    head1 = p1;
       	else
       	    p2 -> next = p1;
       	p2 = p1;
       	}
         return head1;
    }
    struct aaa *link(struct aaa *head1,struct aaa *head2)
    {
         struct aaa *p1;
         p1 = head1;
         while (p1 -> next != NULL)
              p1 = p1 -> next;
         p1 -> next = head2;
         return head1;
    }
    void print(struct aaa *head3)
    {
    	struct aaa *temp;
    	temp = head3;
    	printf("%d", temp -> xx);
    	temp = temp -> next;
    	while (temp != NULL)
    	{
    		printf(" %d", temp -> xx);
    		temp = temp -> next;
    		}
    		printf("\n");
    	}
    
    

    C++ :

    #include<stdio.h>
    #include<vector>
    using namespace std;
    
    int main()
    {
    	int m,n;
    	int x;
    	//freopen("in.txt","r",stdin);
    	while(scanf("%d",&m)!=EOF)
    	{
    		vector<int>data;
    		for(int i=0;i<m;i++)
    		{
    			scanf("%d",&x);
    			data.push_back(x);
    		}
    		scanf("%d",&n);
    		for(int i=0;i<n;i++)
    		{
    			scanf("%d",&x);
    			data.push_back(x);
    		}
    		vector<int>::iterator it=data.begin();
    		printf("%d",*(it));
    		it++;
    		for(;it!=data.end();it++)
    			printf(" %d",*(it));
    		printf("\n");	
    	}
    	return 0;
    }
    
    • 1

    信息

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