鏁版嵁缁撴瀯瀹為獙涔嬮摼琛ㄥ洓锛氭湁搴忛摼琛ㄧ殑褰掑苟

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了鏁版嵁缁撴瀯瀹為獙涔嬮摼琛ㄥ洓锛氭湁搴忛摼琛ㄧ殑褰掑苟相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/ext' title='ext'>ext   return   def   output   hint   鍚堝苟   form   printf   default   

鏁版嵁缁撴瀯瀹為獙涔嬮摼琛ㄥ洓锛氭湁搴忛摼琛ㄧ殑褰掑苟

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description

鍒嗗埆杈撳叆涓や釜鏈夊簭鐨勬暣鏁板簭鍒楋紙鍒嗗埆鍖呭惈M鍜孨涓暟鎹級锛屽缓绔嬩袱涓湁搴忕殑鍗曢摼琛紝灏嗚繖涓や釜鏈夊簭鍗曢摼琛ㄥ悎骞舵垚涓轰竴涓ぇ鐨勬湁搴忓崟閾捐〃锛屽苟渚濇杈撳嚭鍚堝苟鍚庣殑鍗曢摼琛ㄦ暟鎹€?/div>

Input

绗竴琛岃緭鍏涓嶯鐨勫€硷紱 
绗簩琛屼緷娆¤緭鍏涓湁搴忕殑鏁存暟锛?br />绗笁琛屼緷娆¤緭鍏涓湁搴忕殑鏁存暟銆?/div>

Output

杈撳嚭鍚堝苟鍚庣殑鍗曢摼琛ㄦ墍鍖呭惈鐨凪+N涓湁搴忕殑鏁存暟銆?/div>

Sample Input

6 5
1 23 26 45 66 99
14 21 28 50 100

Sample Output

1 14 21 23 26 28 45 50 66 99 100

Hint

涓嶅緱浣跨敤鏁扮粍锛?/div>

Source

 

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 struct node
 4 {
 5     int data;
 6     struct node *next;
 7 };
 8 struct node *Creat(int n)
 9 {
10     struct node *head, *tail, *p;
11     int i;
12     head=(struct node *)malloc(sizeof(struct node));
13     head->next=NULL;
14     tail=head;
15     for(i=1;i<=n;i++)
16     {
17         p=(struct node *)malloc(sizeof(struct node));
18         scanf("%d",&p->data);
19         p->next=NULL;
20         tail->next=p;
21         tail=p;
22     }
23     return head;
24 }
25 
26 struct node * Merge(struct node *head1, struct node *head2)
27 {
28     struct node *p1, *p2, *tail;
29     p1=head1->next;
30     p2=head2->next;
31     tail=head1;
32     free(head2);
33     while(p1&&p2)
34     {
35     if(p1->data < p2->data)
36         {
37             tail->next=p1;
38             tail=p1;
39             p1=p1->next;
40         }
41         else
42         {
43             tail->next=p2;
44             tail=p2;
45             p2=p2->next;
46         }
47     }
48     if(p1)
49         tail->next=p1;
50     else
51         tail->next=p2;
52     return(head1);
53 }
54 
55 int main()
56 {
57     struct node * head1, *head2, *p;
58     int n, m;
59     scanf("%d %d",&n,&m);
60     head1=Creat(n);
61     head2=Creat(m);
62     p=Merge(head1,head2);
63     while(p->next->next!=NULL)
64     {
65         printf("%d ",p->next->data);
66         p=p->next;
67     }
68     printf("%d
",p->next->data);
69     return 0;
70 }

以上是关于鏁版嵁缁撴瀯瀹為獙涔嬮摼琛ㄥ洓锛氭湁搴忛摼琛ㄧ殑褰掑苟的主要内容,如果未能解决你的问题,请参考以下文章

鍚堝苟鐨勮壓鏈?.0锛氬悎骞堕摼琛ㄣ€佹暟缁勩€佷簩鍙夋爲

鍗曢摼琛ㄧ殑瀛︿範

绠楁硶鏁版嵁缁撴瀯01 /绠楁硶鏁版嵁缁撴瀯姒傝堪

python鍐呯疆鏁版嵁缁撴瀯

鏁版嵁缁撴瀯-C璇█瀹炵幇-閾炬爤

鏁版嵁缁撴瀯鐭ヨ瘑妗嗘灦