Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package stvorec;
- import java.io.*;
- import java.util.Scanner;
- public class Stvorec {
- static void vypis(char[][] a) {
- /* vypiseme cisla v matici a na konzolu */
- for (char[] riadok : a) {
- for (char x : riadok) {
- System.out.print(" " + x);
- }
- System.out.println();
- }
- }
- static void pocitaj(char[][] echt, int [][] pocty, int x, int y){
- if (pocty[y][x]!=0) return;
- if (((x+1) >= echt[0].length)||((y+1) >= echt.length)) {
- pocty[y][x]=1;
- return;
- }
- if (pocty[y][x+1]==0){
- pocitaj (echt,pocty,x+1,y);
- }
- if (pocty[y+1][x]==0){
- pocitaj (echt,pocty,x,y+1);
- }
- if (pocty[y+1][x+1]==0){
- pocitaj (echt,pocty,x+1,y+1);
- }
- char ja = echt[y][x];
- if ((echt[y+1][x]!=ja)||(echt[y][x+1]!=ja)||(echt[y+1][x+1]!=ja)){
- pocty[y][x]=1;
- return;
- }
- int tmp=Math.min(pocty[y][x+1], Math.min(pocty[y+1][x], pocty[y+1][x+1]));
- pocty [y][x] = tmp+1;
- }
- public static void main(String[] args)
- throws java.io.IOException {
- //nacitanie prveho riadku nech viem dlzku
- Scanner s = new Scanner(System.in);
- String riadok;
- char[][] a = new char [100][];
- int counter = 0;
- riadok = s.nextLine();
- while (!riadok.equals(".")){
- a[counter] = riadok.toCharArray();
- counter++;
- riadok = s.nextLine();
- }
- char[][] echtpole = new char [counter][];
- System.arraycopy(a, 0, echtpole, 0, counter);
- int n = echtpole.length;
- int m = echtpole[0].length;
- int [][] pocty = new int [n][m];
- pocitaj (echtpole, pocty, 0, 0);
- for (int i=0; i<pocty.length; i++){
- for (int j=0; j<pocty[i].length; j++){
- System.out.print(pocty[i][j]);
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement