PAT乙级1025

https://pintia.cn/problem-sets/994805260223102976/problems/994805296180871168

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<string.h>
 4 #include<algorithm>
 5 #include<cmath>
 6 #include<vector>
 7 #include<map>
 8 #define ms(x,n) memset(x,n,sizeof x);
 9 using namespace std;
10 const int maxn=100005;
11 int a,b,c;
12 struct node
13 {
14     int address;
15     int data;
16     int next;
17 }e[maxn];
18 
19 int main()
20 {
21     int start,str;
22     cin>>start>>b>>c;//起始节点,节点个数,反转k值
23     map<int,node> m;
24     for(int i=0;i<b;i++)
25         {
26             scanf("%d",&str);
27             scanf("%d %d",&m[str].data,&m[str].next);
28         }
29       //把map中的数倒到结构体中
30       //如果不用map直接存数到结构体中,那么构成的不是链表
31       //用map的话,以结构体的顺序下去就是一条链
32      for(int i=0;i<b;i++)
33         {
34             e[i].address=start;
35             e[i].data=m[start].data;
36             start=m[start].next;
37             if(start==-1)
38                 b=i+1;//记录所有有效的地址
39             if((i+1)%c==0)
40                 reverse(e+i+1-c,e+i+1);
41         }
42     for(int i=0;i<b;i++)
43         {
44             printf("%05d %d",e[i].address,e[i].data);
45             if(i!=b-1)
46                 printf(" %05d\n",e[i+1].address);
47             else
48                 printf(" -1");
49         }
50     return 0;
51 }

 

转载于:https://www.cnblogs.com/zuiaimiusi/p/10876885.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值