13609 - DS_2022_HW1_LinkedList   

Description

In this homework, we need to rotate linked lists.

  1. For each test case, there exists M linked lists.
  2. For each linked list with length N, we want to rotate it every K elements.
  3. That is, the ith­ number will be rotate to (K-i+1)th number.
  4. If last n < K elements are un-rotated, you don’t need to rotate it.

Input

There is one number in the first line, which is denoted as M, indicating the number of linked lists. For each linked list, there are two numbers N and K. The linked list consists of N numbers in next line.

  • M ≤ 1,500
  • N ≤ 100,000
  • K ≤ 1,000
  • -231  node's value ≤ 231-1

Output

Print all rotated linked lists and print “\n” between two linked lists.

Sample Input  Download

Sample Output  Download

Tags




Discuss