题目
Given a singly linked list L. Let us consider every K nodes as a block (if there are less than K nodes at the end of the list, the rest of the nodes are still considered as a block). Your job is to reverse all the blocks in L. For example, given L as 1→2→3→4→5→6→7→8 and K as 3, your output must be 7→8→4→5→6→1→2→3.
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 (≤10e5) which is the total number of nodes, and a positive K (≤N) which is the size of a block. 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

这篇博客介绍了PAT甲级编程题1165 Block Reversing,要求对每K个节点为一个块的链表进行反转。文章提供了输入输出规格,并给出了样例输入和输出。博主分享了解题思路,包括与另一题目的相似之处,以及一种优化解法的链接,同时提到了该优化解法在处理最后一个测试点时存在的问题。
最低0.47元/天 解锁文章
961





