鏁版嵁缁撴瀯瀹為獙涔嬮摼琛ㄥ洓锛氭湁搴忛摼琛ㄧ殑褰掑苟
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>
绗簩琛屼緷娆¤緭鍏涓湁搴忕殑鏁存暟锛?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 }
以上是关于鏁版嵁缁撴瀯瀹為獙涔嬮摼琛ㄥ洓锛氭湁搴忛摼琛ㄧ殑褰掑苟的主要内容,如果未能解决你的问题,请参考以下文章