Advertisement
Guest User

Untitled

a guest
Mar 1st, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.16 KB | None | 0 0
  1. package stvorec;
  2.  
  3. import java.io.*;
  4. import java.util.Scanner;
  5.  
  6. public class Stvorec {
  7.  
  8.     static void vypis(char[][] a) {
  9.         /* vypiseme cisla v matici a na konzolu */
  10.         for (char[] riadok : a) {
  11.             for (char x : riadok) {
  12.                 System.out.print(" " + x);
  13.             }
  14.             System.out.println();
  15.         }
  16.     }
  17.    
  18.     static void pocitaj(char[][] echt, int [][] pocty, int x, int y){
  19.         if (pocty[y][x]!=0) return;
  20.         if (((x+1) >= echt[0].length)||((y+1) >= echt.length)) {
  21.             pocty[y][x]=1;
  22.             return;
  23.         }    
  24.         if (pocty[y][x+1]==0){
  25.             pocitaj (echt,pocty,x+1,y);
  26.         }
  27.         if (pocty[y+1][x]==0){
  28.             pocitaj (echt,pocty,x,y+1);
  29.         }
  30.         if (pocty[y+1][x+1]==0){
  31.             pocitaj (echt,pocty,x+1,y+1);
  32.         }
  33.         char ja = echt[y][x];
  34.        
  35.         if ((echt[y+1][x]!=ja)||(echt[y][x+1]!=ja)||(echt[y+1][x+1]!=ja)){
  36.             pocty[y][x]=1;
  37.             return;
  38.         }
  39.        
  40.         int tmp=Math.min(pocty[y][x+1], Math.min(pocty[y+1][x], pocty[y+1][x+1]));
  41.         pocty [y][x] = tmp+1;
  42.  
  43.     }
  44.    
  45.     public static void main(String[] args)
  46.         throws java.io.IOException {
  47.        
  48.         //nacitanie prveho riadku nech viem dlzku
  49.         Scanner s = new Scanner(System.in);
  50.         String riadok;
  51.        
  52.         char[][] a = new char [100][];
  53.         int counter = 0;
  54.         riadok = s.nextLine();
  55.         while (!riadok.equals(".")){
  56.            
  57.             a[counter] = riadok.toCharArray();
  58.             counter++;
  59.             riadok = s.nextLine();
  60.         }
  61.        
  62.         char[][] echtpole = new char [counter][];
  63.         System.arraycopy(a, 0, echtpole, 0, counter);
  64.        
  65.         int n = echtpole.length;
  66.         int m = echtpole[0].length;
  67.        
  68.         int [][] pocty = new int [n][m];
  69.        
  70.         pocitaj (echtpole, pocty, 0, 0);
  71.        
  72.  
  73.         for (int i=0; i<pocty.length; i++){
  74.             for (int j=0; j<pocty[i].length; j++){
  75.                 System.out.print(pocty[i][j]);
  76.             }
  77.             System.out.println();
  78.         }
  79.      }
  80.    
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement