41 11 20 3100 4Example Output
3 1 2 4Hint
Author
01 | #include<bits/stdc++.h> |
02 | using namespace std; |
03 |
04 | struct node |
05 | { |
06 | int data; |
07 | node *next; |
08 | }; |
09 | int len; |
10 | node *head; |
11 |
12 | void Insert( int m, int n) |
13 | { |
14 | node *p,*tail; |
15 | tail=head; |
16 | for ( int i=0;i<m&&i<len;i++) //从头结点处一直到序列m点,或者直到指向空 |
17 | tail=tail->next; |
18 | p= new node; |
19 | p->data=n; |
20 | p->next=tail->next; |
21 | tail->next=p; |
22 | len++; |
23 | } |
24 |
25 | void print() |
26 | { |
27 | node *p; |
28 | p=head->next; |
29 | while (p) |
30 | { |
31 | if (p->next) |
32 | printf ( "%d " ,p->data); |
33 | else |
34 | printf ( "%d/n" ,p->data); |
35 | p=p->next; |
36 | } |
37 | } |
38 |
39 | int main() |
40 | { |
41 | int t,m,n; |
42 | while (~ scanf ( "%d" ,&t)) |
43 | { |
44 | head= new node; |
45 | len=0; |
46 | for ( int i=0;i<t;i++) |
47 | { |
48 | scanf ( "%d%d" ,&m,&n); |
49 | Insert(m,n); |
50 | } |
51 | print(); |
52 | } |
53 | return 0; |
54 | } |
新闻热点
疑难解答