CSES - Datatähti 2023 alku - Results
Submission details
Task:Lehmät
Sender:Hinzu
Submission time:2022-11-07 20:07:50 +0200
Language:Java
Status:COMPILE ERROR

Compiler report

input/cows.java:3: error: class Main is public, should be declared in a file named Main.java
public class Main {
       ^
1 error

Code

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int height = sc.nextInt();
        int width = sc.nextInt();

        sc.nextLine();

        int[] first = null;
        int[] last = new int[2];

        char[][] map = new char[width][height];
        for (int h = 0; h < height; h++) {
            String line = sc.nextLine();
            for (int w = 0; w < line.length(); w++) {
                //--
                char c = line.charAt(w);

                if (c == '*') {
                    if (first == null) {
                        first = new int[]{h, w};
                    }
                    last[0] = h;
                    last[1] = w;
                }

                map[w][h] = line.charAt(w);

            }
        }

        int count = 0;
        for (int h = first[0]+1; h < last[0]; h++) {
            for (int w = first[1]+1; w < last[1]; w++) {
                if(map[w][h] == '@') {
                    count++;
                }
            }
        }

        System.out.println(count);

    }
}