9130: List Reshape

内存限制:256 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:2 通过:1

题目描述

    ProtectEMmm is learning to use NumPy.
    She is curious about the reshape function and wants to implement it by hand. For simplicity, hers reshape function reads a non-nested list (which means, all elements in the list are numbers, not a list), and the size of two dimensions of the output list, and then outputs a 2-dimension list with the data, the order and the number of elements unchanged, but with the specified shape.
    A well-formatted Python list can be written as a list of comma-separated values (items) between square brackets []. See the sample input and output for more information.
    The size of each dimension describes the shape of the list. For example, a 2 × 3 list like [[1, 2, 3], [4, 5, 6]], consists of two lists, each of which consists of three numbers.
    ProtectEMmm finished implementing it quickly. Could you implement it as fast as she can?

输入格式

    The first line contains an integer T (1 ≤ T ≤ 50), indicating the number of test cases.
    In each test case:
    The first line contains a string s, indicating the list in Python.
    The second line contains two numbers x, y, the size of each dimension of the output list. Your output list need to consist of x lists, each of which consists of y numbers.
    It is guaranteed that the number of elements in s equals to x · y, all elements in the list are in the range 0 to 1000, and the sum of the number of elements in all test cases does not exceed 5 × 105.

输出格式

    For each test case, you should print a line of string, the result of your reshape operation.
    Note that you need to print exactly one space between every comma and the next item in your output. Do not print any more space at the end of line.

输入样例 复制

4
[3, 1, 4, 1, 5, 9, 2, 6]
2 4
[998, 244, 3, 5, 3]
5 1
[1, 1, 2, 3, 5, 8, 13, 21, 34]
1 9
[2, 3, 5, 7, 11, 13, 17, 19, 23]
3 3

输出样例 复制

[[3, 1, 4, 1], [5, 9, 2, 6]]
[[998], [244], [3], [5], [3]]
[[1, 1, 2, 3, 5, 8, 13, 21, 34]]
[[2, 3, 5], [7, 11, 13], [17, 19, 23]]

分类标签