Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.Arrays;
- public class LtestTwo {
- public static void main(String[] args) throws IOException {
- BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
- int rows = Integer.parseInt(read.readLine());
- int cols = Integer.parseInt(read.readLine());
- char[][] matrix = readCharMatrix(read, rows); // Work
- char[][] matrix2 = readCharMatrix(read, rows, cols); // Work
- //CharTest
- // 5
- // 5
- // a a a a a
- // a a a a a
- // a a a a a
- // a a a a a
- // a a a a a
- //Char test without row col , because they have already been filed .
- // a a a a a
- // a a a a a
- // a a a a a
- // a a a a a
- // a a a a a
- printCharMatrix(matrix); //Work
- System.out.println();
- printCharMatrix(matrix2); //Work
- int[][] intMatrix = readIntMatrix(read); // Work
- printIntMatrix(intMatrix); // Work
- // Int test
- // 5 5
- // 1 2 3 4 5
- // 6 7 8 9 10
- // 11 12 13 14 15
- // 16 17 18 19 20
- // 21 22 23 24 25
- }
- private static char[][] readCharMatrix(BufferedReader read, int rows) throws IOException { // Work
- char[][] matrix = new char[rows][];
- for (int row = 0; row < rows; row++) {
- String line = read.readLine();
- String newString = line.replaceAll("\\s+", "");
- matrix[row] = newString.toCharArray();
- }
- return matrix;
- }
- private static char[][] readCharMatrix(BufferedReader read, int rows, int cols) throws IOException { // Work
- char[][] matrix = new char[rows][cols];
- for (int row = 0; row < rows; row++) {
- char[] line = read.readLine().replaceAll("\\s+", "").toCharArray();
- for (int col = 0; col < cols; col++) {
- matrix[row][col] = line[col];
- }
- }
- return matrix;
- }
- private static void printCharMatrix(char[][] matrix) { // Work
- //System.out.println();
- for (int row = 0; row < matrix.length; row++) {
- for (int col = 0; col < matrix[row].length; col++) {
- System.out.print(matrix[row][col] + " ");
- }
- System.out.println();
- }
- }
- private static int[][] readIntMatrix(BufferedReader read) throws IOException {
- String line = read.readLine();
- String[] split = line.split("\\s+");
- int rows = Integer.parseInt(split[0]);
- int cols = Integer.parseInt(split[1]);
- int[][] matrix = new int[rows][cols];
- for (int row = 0; row < rows; row++) {
- line = read.readLine();
- split = line.split("\\s+");
- for (int col = 0; col < cols; col++) {
- matrix[row][col] = Integer.parseInt(split[col]);
- }
- }
- return matrix;
- }
- private static void printIntMatrix(int[][] matrix) {
- for (int row = 0; row < matrix.length; row++) {
- for (int col = 0; col < matrix[row].length; col++) {
- System.out.print(matrix[row][col] + " ");
- }
- System.out.println();
- }
- }
- private static String trimAndDeleteBlanks(BufferedReader read) throws IOException {
- String line = read.readLine().trim();
- while (line.length() == 0) {
- line = read.readLine().trim();
- }
- return line;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement