被少写个0坑死了
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
const int maxn=100100;//这里如果少写个0就会出错!!!
struct node{
int address,data,next;
int order;
}_node[maxn];
bool cmp(node a,node b){
return a.order<b.order;
}
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
for(int i=0;i<maxn;i++){
_node[i].order=maxn;
}
int begin,n,k,address;
scanf("%d%d%d",&begin,&n,&k);
for(int i=0;i<n;i++){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
_node[a].address=a;
_node[a].data=b;
_node[a].next=c;
}
int p=begin;
int count=0;
while(p!=-1){
_node[p].order=count;
count++;
p=_node[p].next;
}
sort(_node,_node+maxn,cmp);
int m=count;
int mm=m/k;
for(int i=0;i<mm;i++){
for(int j=(i+1)*k-1;j>(i+1)*k-k;j--){
printf("%05d %d %05d\n",_node[j].address,_node[j].data,_node[j-1].address);
}
printf("%05d %d ",_node[(i+1)*k-k].address,_node[(i+1)*k-k].data);
if(i<mm-1){
printf("%05d\n",_node[(i+2)*k-1].address);
}else{
if(m%k==0){
//cout<<-1<<endl;
printf("-1\n");
}else{
printf("%05d\n",_node[(i+1)*k].address);
for(int t=mm*k;t<m;t++){
printf("%05d %d ",_node[t].address,_node[t].data);
if(t<m-1){
printf("%05d\n",_node[t+1].address);
}
else{
printf("-1\n");
}
}
}
}
}
return 0;
}