13811 - I hate winter vacation   

Description

Jacky hates winter vacation because he learned the knowledge of coding and he met a lot of friends.

Fortunately, he comes up with an idea that he can keep practicing programming by modifying the final practice!

Good job!

nc

The problem is modified from problem 13412.

Given the head of the linked list containing multiple groups (the size of each group is k ), sort the nodes inside each group at a time.

k is a positive integer and is less than or equal to the length of the linked list.

If the number of nodes is not a multiple of k, then the left-out nodes in the end should remain the same order.

You are not allowed to alter the values in each node.

All the numbers in the linked-list is a unique number.

For example, when k = 2:

Note that it is a partial-judge problem that you need to implement the function:

Node* Solver(Node* head, int k)

 

Input

The first line is composed of a sequence of integer(1<= val <=100000000), which represents the values of the linked list.

The input stops when read in '-1' ('-1' is not a part of the 2 linked-lists).

The second line is k,  the size of the group that will be reversed.(1 <= k <= length of the linked list)

Output

The values of the group-based reversed linked-list.

The values are separated by a whitespace and the output is also ended with a whitespace.

Sample Input  Download

Sample Output  Download

Partial Judge Code

13811.c

Partial Judge Header

13811.h

Tags




Discuss