博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
pat02-线性结构1. Reversing Linked List (25)
阅读量:4507 次
发布时间:2019-06-08

本文共 1717 字,大约阅读时间需要 5 分钟。

02-线性结构1. Reversing Linked List (25)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue

Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K = 3, then you must output 3→2→1→6→5→4; if K = 4, you must output 4→3→2→1→5→6.

Input Specification:

Each input file contains one test case. For each case, the first line contains the address of the first node, a positive N (<= 105) which is the total number of nodes, and a positive K (<=N) which is the length of the sublist to be reversed. The address of a node is a 5-digit nonnegative integer, and NULL is represented by -1.

Then N lines follow, each describes a node in the format:

Address Data Next

where Address is the position of the node, Data is an integer, and Next is the position of the next node.

Output Specification:

For each case, output the resulting ordered linked list. Each node occupies a line, and is printed in the same format as in the input.

Sample Input:
00100 6 400000 4 9999900100 1 1230968237 6 -133218 3 0000099999 5 6823712309 2 33218
Sample Output:
00000 4 3321833218 3 1230912309 2 0010000100 1 9999999999 5 6823768237 6 -1

 

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 using namespace std;10 struct node{11 int now,next,data;12 };13 node mem[100005];14 vector
v;15 int main(){16 //freopen("D:\\INPUT.txt","r",stdin);17 int h,now,data,next,num,k,temp;18 scanf("%d %d %d",&h,&num,&k);19 int i;20 for(i=0;i

 

转载于:https://www.cnblogs.com/Deribs4/p/4720817.html

你可能感兴趣的文章
Response.StatusCode的HTTP状态代码列表
查看>>
win7下maven安装和配置
查看>>
C# 多线程编程 ThreadStart ParameterizedThreadStart
查看>>
Android Camera Parameters 方法出错,求教
查看>>
一个仿照系统UIAlertView写的提示框
查看>>
Genymotion集成到Eclipse
查看>>
代码简洁之四 统一抽象层次
查看>>
IOS 缩放图片常用方法
查看>>
软件工程课
查看>>
Pycharm-连接服务器
查看>>
[Leetcode] The Skyline Problem
查看>>
okhttp异步请求流程和源码分析
查看>>
【集合框架】JDK1.8源码分析之Comparable && Comparator(九)
查看>>
Flutter之内置动画(转)
查看>>
uni-app中onLoad不起作用
查看>>
多线程概述
查看>>
Linux_ubuntu命令-用户、权限管理
查看>>
Knowladge_网站学习_RSS 学习
查看>>
TCP/IP,Web世界的基本规则
查看>>
c++ 子类构造函数初始化及父类构造初始化
查看>>