#include<stdio.h>
int main(void)
{
int a[100000][2]={0},b[100000][2]={0},next,n,k,t1,t2,t3,start,count=0;
scanf("%d %d %d",&next,&n,&k);
for(int i=0;i<n;i++)
{
scanf("%d %d %d",&t1,&t2,&t3);
a[t1][0]=t2,a[t1][1]=t3;
}
while(next!=-1)
{
b[count][0]=next;
b[count++][1]=a[next][0];
next=a[next][1];
}
n=(count+k-1)/k;
start=n;
while(n--)
{
int i=n*k;
if(n==0&&n==start-1)
{
for(;i<count;i++)
i==count-1?printf("%05d %d -1",b[i][0],b[i][1]):printf("%05d %d %05d\n",b[i][0],b[i][1],b[i+1][0]);
}
else if(n==start-1)
{
for(;i<count;i++)
i==count-1?printf("%05d %d %05d\n",b[i][0],b[i][1],b[(n-1)*k][0]):printf("%05d %d %05d\n",b[i][0],b[i][1],b[i+1][0]);
}
else if(n!=0)
{
for(;i<(n+1)*k;i++)
i==(n+1)*k-1?printf("%05d %d %05d\n",b[i][0],b[i][1],b[(n-1)*k][0]):printf("%05d %d %05d\n",b[i][0],b[i][1],b[i+1][0]);
}
else
{
for(;i<(n+1)*k;i++)
i==(n+1)*k-1?printf("%05d %d -1",b[i][0],b[i][1]):printf("%05d %d %05d\n",b[i][0],b[i][1],b[i+1][0]);
}
}
return 0;
}
PTAbasic 1110区块反转C语言
最新推荐文章于 2023-05-23 17:15:02 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)