CSES - Datatähti 2023 alku - Results
Submission details
Task:Lehmät
Sender:adex720
Submission time:2022-10-31 16:28:08 +0200
Language:Java
Status:COMPILE ERROR

Compiler report

input/B.java:26: error: bad operand types for binary operator '&&'
                        if (rivi.charAt(i1+1) && alkanut){
                                              ^
  first type:  char
  second type: boolean
1 error

Code

import java.util.Scanner;

public class B {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String koot[] = scanner.nextLine().split(" ");

        int korkeus = Integer.parseInt(koot[0]);
        int leveys = Integer.parseInt(koot[1]);

        boolean alkanut = false;
        boolean loppunut = false;
        int lehmia = 0;

        for (int i = 0; i < korkeus; i++) {
            String rivi = scanner.nextLine();
            if (loppunut) continue;

            boolean sisalla = false;
            for (int i1 = 0; i1 < leveys; i1++) {
                char nykyinen = rivi.charAt(i1);
                if (nykyinen == '*') {
                    if (sisalla ) {
                        if (rivi.charAt(i1+1) && alkanut){
                            loppunut = true;
                            break;
                        }

                        sisalla = false;
                        break;
                    } 

                    alkanut = true;
                    sisalla = true;

                    continue;
                }

                if (nykyinen == '@' && sisalla) {
                    lehmia++;
                }

            }

        }
        
        System.out.print(lehmia);

    }

}