13412 - I hate Christmas   

Description

One day, you become a santa claus and have to send everyone gifts.

 

There is a line of people, and each one has a non-unique number card which represents what gifts they will receive.

(Because you are a smart santa claus, you use linked-list to record the numbers)

However, when you see there are so many couples standing together, you feel so angry and decide to rearrange the order with the following rule:

 

Given the head of the linked list containing multiple groups (the size of each group is k ), reverse 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.

 

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

13412.c

Partial Judge Header

13412.h

Tags




Discuss