Rezultati

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

Test Točke Porabljen spomin Porabljen čas Status
#1 10/10 35,082 MiB 0,000 s OK
#2 10/10 34,668 MiB 0,000 s OK
#3 10/10 34,398 MiB 0,000 s OK
#4 10/10 37,785 MiB 0,000 s OK
#5 10/10 34,707 MiB 0,000 s OK
#6 10/10 34,633 MiB 0,000 s OK
#7 10/10 35,195 MiB 0,000 s OK
#8 10/10 35,801 MiB 0,000 s OK
#9 10/10 37,957 MiB 0,000 s OK
#10 10/10 38,012 MiB 0,000 s OK

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

/**
 * Created by zan on 4/20/17.
 */
public class Hallway {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        char[] nums = scanner.next().toCharArray();

        int left = 0;
        int right = 0;

        boolean leftState = true;
        boolean rightState = false;
        for (char num : nums) {
            if (num == '1' && !leftState) {
                left++;
            } else if (num == '0' && leftState) {
                left++;
            }

            if (num == '1' && !rightState) {
                right++;
            } else if (num == '0' && rightState) {
                right++;
            }

            leftState = !leftState;
            rightState = !rightState;
        }

        System.out.println(Math.min(left, right));
    }
}