Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- import java.util.Stack;
- public class First {
- public class lake{
- int x;
- int y;
- int cells;
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner s = new Scanner(System.in);
- int n = s.nextInt();
- int m = s.nextInt();
- int k = s.nextInt();
- String [] map = new String[n+2];
- String temp = "";
- for(int i = 0; i < m+2; i++) {
- temp += "#";
- }
- map[0] = temp;
- s.nextLine();
- for(int i = 1; i <= n; i++) {
- String t = s.nextLine();
- map[i] = ".";
- map[i] += t;
- map[i] += ".";
- }
- map[n+1] = temp;
- for(int i = 0; i < n+2; i++) {
- System.out.print(map[i]);
- System.out.println();
- }
- ArrayList<lake> myLakes = new ArrayList<>();
- temp = "";
- int x1 = 0;
- int y1 = 0;
- Stack<Character> st = new Stack<>();
- int counter = 0;
- for(int i = 1; i < n+1; i++) {
- temp = map[i];
- for(int j = 1; j < temp.length()-1; j++) {
- if(temp.charAt(j) == '.' && temp.charAt(j-1) != '#' && temp.charAt(j+1) != '#' && map[i-1].charAt(j) != '#' &&
- map[i+1].charAt(j) != '#' ) {
- st.push(temp.charAt(j));
- counter++;
- x1 = j;
- y1 = i;
- }
- else {
- lake l = new lake();
- l.cells = counter;
- l.x = x1;
- l.y = y1;
- myLakes.add(l);
- while(!st.isEmpty()) {
- st.pop();
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement