41 11 20 3100 4Example Output
3 1 2 4Hint
代码如下:
#include <stdio.h> #include <stdlib.h> struct node { int data; struct node *next; }; int len; struct node *head; void Insert(int m,int n) { struct node *p,*q; p=head; for(int i=0;i<m&&i<len;i++) p=p->next; q= (struct node *)malloc(sizeof(struct node)); q->data=n; q->next=p->next; p->next=q; len++; } void print() { struct node *p; p=head->next; while(p) { if(p->next) printf("%d ",p->data); else printf("%d/n",p->data); p=p->next; } } int main() { int t,m,n; while(~scanf("%d",&t)) { head=(struct node *)malloc(sizeof(struct node)); len=0; for(int i=0;i<t;i++) { scanf("%d%d",&m,&n); Insert(m,n); } print(); } return 0; }
新闻热点
疑难解答