二、参考代码
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
int first, k, n, sum = 0;
cin >> first >> n >> k;
int temp, data[100010], next[100010], list[100010], result[100010];
for(int i = 0; i < n; i++){
cin >> temp;
cin >> data[temp] >> next[temp];
}
while(first != -1){
list[sum++] = first;
first = next[first];
}
for(int i = 0; i < sum; i++) result[i] = list[i];
for(int i = 0; i < (sum - sum%k); i++){
result[i] = list[i / k * k + k - 1 - i % k];
}
for(int i = 0; i < sum - 1; i++){
printf("%05d %d %05d\n", result[i], data[result[i]], result[i+1]);
}
printf("%05d %d -1", result[sum - 1], data[result[sum-1]]);
return 0;
}
原文地址:https://www.cnblogs.com/tsruixi/p/12257482.html
时间: 2024-10-07 12:20:32