可以直接在函数内输出而不返回出来。

 1 #include <iostream>
 2 #include <algorithm>
 3 using namespace std;
 4 
 5 struct node{
 6     int ad, next, value;
 7 };
 8 
 9 void backs(node a[], node b[], int n1, int n2){
10     node c[100000];
11     reverse(b, b+n2);
12     int l1=0, l2=0, l3=0;
13     while(l2 < n2){
14         c[l3++] = a[l1++];
15         c[l3++] = a[l1++];
16         c[l3++] = b[l2++];
17     }
18     while(l1 < n1) c[l3++] = a[l1++];
19     for(int i = 0; i < l3-1; i++) printf("%05d %d %05d\n", c[i].ad, c[i].value, c[i+1].ad);
20     printf("%05d %d -1", c[l3-1].ad, c[l3-1].value);
21 }
22 
23 int main(){
24     int d1, d2, n, k, n1 = 0, n2 = 0;
25     cin >> d1 >> d2 >> n;
26     node datas[100000], a, s1[100000], s2[100000];
27     for(int i = 0; i < n; i++){
28         cin >> a.ad >> a.value >> a.next;
29         datas[a.ad] = a;
30     }
31     k = d1;
32     while(k != -1){
33         s1[n1++] = datas[k];
34         k = datas[k].next;
35     }
36     k = d2;
37     while(k != -1){
38         s2[n2++] = datas[k];
39         k = datas[k].next;
40     }
41     if(n1 > n2) backs(s1, s2, n1, n2);
42     else backs(s2, s1, n2, n1);
43     return 0;
44 }

 

posted on 2022-01-18 09:43  千咲  阅读(83)  评论(0)    收藏  举报