首页 > 其他 > 详细

The utility class Collections Rotating table

时间:2020-09-27 21:52:46      阅读:41      评论:0      收藏:0      [点我收藏+]

You have a table of integer numbers. You should rotate rows of the table by the specified distance.

Try to use collections and standard methods for them.

Input data format

The first line contains two numbers: a number of rows and a number of columns of the table.

The following lines describe rows of the table. In each row, all elements are separated by spaces.

The last line consists of one number, which is the distance for rotating.

Output data format

Output the resulting table. Separate numbers by a single space in the output.

Report a typo
Sample Input 1:

3 3
1 1 1
2 2 2
3 3 3
1
Sample Output 1:

3 3 3
1 1 1
2 2 2

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<String> list = new ArrayList<>();
        int rowsAndCols = Integer.parseInt(sc.nextLine().split(" ")[0]);

        for (int i = 0; i < rowsAndCols; i++) {
            list.add(sc.nextLine());
        }

        Collections.rotate(list, sc.nextInt());

        list.forEach(System.out::println);
    }
}

The utility class Collections Rotating table

原文:https://www.cnblogs.com/longlong6296/p/13740893.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!