Advertisement
Lusien_Lashans

Laba2

Apr 26th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.70 KB | None | 0 0
  1. package com.company;
  2. import java.nio.file.Files;
  3. import java.nio.file.Paths;
  4. import java.util.ArrayList;
  5. import java.io.InputStream;
  6. import java.nio.file.Path;
  7. import java.io.File;
  8. import java.io.*;
  9.  
  10. public class Main {
  11.  
  12.     public static String str;
  13.     public static int HEIGHT;
  14.     public static int WIDTH;
  15.  
  16.     public static int[] tor;
  17.     public static int[][] matrix;
  18.     public static boolean[][] labirint;
  19.  
  20.     public static void main(String[] args) {
  21.         Path p = Paths.get("C:\\Users\\acer\\IdeaProjects\\Lobe\\src\\com\\company\\Input");
  22.         InputStream in;
  23.         try{
  24.             in = Files.newInputStream(p);
  25.             byte[] bytes = new byte[in.available()];
  26.             in.read(bytes);
  27.             String s = new String(bytes, "cp1251");
  28.             str = s;
  29.         }
  30.         catch (Exception e){
  31.             return;
  32.         }
  33.         String lolo = str.replaceAll("\\p{Cntrl}", ",");
  34.         String help = lolo.replaceAll(" ", ";");
  35.         String d = help.replaceAll(",,", ";");
  36.         String[] s = d.split(";");
  37.         tor = new int[s.length];
  38.  
  39.         int c = 0;
  40.         for (String i: s){
  41.             tor[c] = Integer.parseInt(i);
  42.             c++;
  43.         }
  44.  
  45.         HEIGHT = tor[0];
  46.         WIDTH = tor [1];
  47.  
  48.         matrix = new int[HEIGHT][WIDTH];
  49.  
  50.         int yo = 2;
  51.         for (int i=0; i<HEIGHT; i++){
  52.             for (int j=0; j<WIDTH; j++){
  53.                 matrix[i][j] = tor[yo];
  54.                 yo++;
  55.             }
  56.         }
  57.  
  58.         for (int i = 0; i<HEIGHT; i++){
  59.             for (int j = 0; j<WIDTH; j++){
  60.                 System.out.print(matrix[i][j]);
  61.             }
  62.             System.out.println();
  63.         }
  64.  
  65.  
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement