제출 #410034

#제출 시각아이디문제언어결과실행 시간메모리
410034PikaChu999Tracks in the Snow (BOI13_tracks)Java
컴파일 에러
0 ms0 KiB
/*
5 8
FFR.....
.FRRR...
.FFFFF..
..RRRFFR
.....FFF
*/
import java.util.*;
import java.io.*;

public class Main {
  public static int height; 
  public static int width; 
  public static String[][] grid; 
  public static int res = 0;
  public static int[] xCoors = {0,0,-1,1};
  public static int[] yCoors = {1,-1,0,0};
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer details = new StringTokenizer(br.readLine());
    height = Integer.parseInt(details.nextToken());
    width = Integer.parseInt(details.nextToken());
    grid = new String[height][width];
    for(int x = 0; x < height; x++){
      String row = br.readLine();
      for(int y = 0; y < width; y++){
        grid[x][y] = String.valueOf(row.charAt(y));
      }
    }
    floodfill();
    System.out.println(res);
    br.close();
  }
  public static void floodfill(){
    boolean[][] seen = new boolean[height][width];
    for(int a = 0; a < height; a++){
      for(int b = 0; b < width; b++){
        if(!seen[a][b] && !grid[a][b].equals(".")){
          res++;
          String animal = grid[a][b];
          boolean otherAnimal = false; 
          Queue<Coord> tree = new LinkedList<Coord>();
          tree.add(new Coord(a, b));
          while(!tree.isEmpty()){
            Coord current = tree.poll(); 
            if(!seen[current.x][current.y]){
              if(!grid[current.x][current.y].equals(animal)) otherAnimal = true;
              System.out.println(current + " " + grid[current.x][current.y]);
              seen[current.x][current.y] = true; 
              for(int c = 0; c < 4; c++){
                int xCoord = current.x + xCoors[c];
                int yCoord = current.y + yCoors[c];
                if(xCoord < 0 || yCoord < 0 || xCoord >= height || yCoord >= width || grid[xCoord][yCoord].equals(".")) continue; 
                tree.add(new Coord(xCoord, yCoord));
              }
            }
          }
          if(otherAnimal) res++;
        }
      }
    }
  }
}

class Coord{
  int x; 
  int y;
  public Coord(int xC, int yC){
    x = xC;
    y = yC;
  }
  public String toString(){
    return x + " " + y;
  }
}

컴파일 시 표준 에러 (stderr) 메시지

tracks.java:12: error: class Main is public, should be declared in a file named Main.java
public class Main {
       ^
1 error