Rezultati

Up. imeNalogaJezikRezultatČas oddaje
jam-2017 Hodnik Java 100/100OK 20. apr '17 @ 16:39

Test Točke Porabljen spomin Porabljen čas Status
#1 10/10 35,613 MiB 0,000 s OK
#2 10/10 34,746 MiB 0,000 s OK
#3 10/10 27,707 MiB 0,000 s OK
#4 10/10 30,797 MiB 0,000 s OK
#5 10/10 37,805 MiB 0,000 s OK
#6 10/10 38,168 MiB 0,000 s OK
#7 10/10 31,051 MiB 0,000 s OK
#8 10/10 31,031 MiB 0,000 s OK
#9 10/10 32,359 MiB 0,000 s OK
#10 10/10 31,293 MiB 0,000 s OK

Ocenjevani program (Hodnik.java):
import java.util.Scanner;

public class Hodnik {

    static int counter1, counter2;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        int len = s.length();
        for (int i = 0; i < len; i++) {
            boolean prizgana = s.charAt(i) == '1';

            if (prizgana != (i % 2 == 0)) {
                counter1++;
            }

            if (prizgana != (i % 2 == 1)) {
                counter2++;
            }
        }
        System.out.println(counter1 < counter2 ? counter1 : counter2);
    }
}