Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3. import java.util.Stack;
  4.  
  5. public class First {
  6.  
  7.     public class lake{
  8.         int x;
  9.         int y;
  10.         int cells;
  11.     }
  12.    
  13.    
  14.     public static void main(String[] args) {
  15.         // TODO Auto-generated method stub
  16.  
  17.         Scanner s = new Scanner(System.in);
  18.        
  19.         int n = s.nextInt();
  20.         int m = s.nextInt();
  21.         int k = s.nextInt();
  22.        
  23.         String [] map = new String[n+2];
  24.         String temp = "";
  25.         for(int i = 0; i < m+2; i++) {
  26.             temp += "#";
  27.         }
  28.         map[0] = temp;
  29.         s.nextLine();
  30.         for(int i = 1; i <= n; i++) {
  31.             String t = s.nextLine();
  32.             map[i] = ".";
  33.             map[i] += t;
  34.             map[i] += ".";
  35.            
  36.         }
  37.         map[n+1] = temp;
  38.        
  39.         for(int i = 0; i < n+2; i++) {
  40.            
  41.             System.out.print(map[i]);
  42.             System.out.println();
  43.            
  44.         }
  45.        
  46.         ArrayList<lake> myLakes = new ArrayList<>();
  47.         temp = "";
  48.         int x1 = 0;
  49.         int y1 = 0;
  50.         Stack<Character> st = new Stack<>();
  51.         int counter = 0;
  52.         for(int i = 1; i < n+1; i++) {
  53.             temp = map[i];
  54.             for(int j = 1; j < temp.length()-1; j++) {
  55.                 if(temp.charAt(j) == '.' && temp.charAt(j-1) != '#' && temp.charAt(j+1) != '#' && map[i-1].charAt(j) != '#' &&
  56.                         map[i+1].charAt(j) != '#' ) {
  57.                     st.push(temp.charAt(j));
  58.                     counter++;
  59.                     x1 = j;
  60.                     y1 = i;
  61.                 }
  62.                 else {
  63.                     lake l = new lake();
  64.                     l.cells = counter;
  65.                     l.x = x1;
  66.                     l.y = y1;
  67.                     myLakes.add(l);
  68.                     while(!st.isEmpty()) {
  69.                         st.pop();
  70.                     }
  71.                 }
  72.             }
  73.            
  74.            
  75.         }
  76.        
  77.  
  78.        
  79.        
  80.        
  81.            
  82.            
  83.            
  84.        
  85.        
  86.        
  87.        
  88.        
  89.        
  90.        
  91.     }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement