Rezultati

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

Test Točke Porabljen spomin Porabljen čas Status
#1 10/10 37,500 MiB 0,000 s OK
#2 10/10 35,551 MiB 0,000 s OK
#3 10/10 39,730 MiB 0,000 s OK
#4 10/10 32,648 MiB 0,000 s OK
#5 10/10 28,922 MiB 0,000 s OK
#6 10/10 34,281 MiB 0,000 s OK
#7 10/10 34,664 MiB 0,000 s OK
#8 10/10 37,762 MiB 0,000 s OK
#9 10/10 31,563 MiB 0,000 s OK
#10 10/10 37,453 MiB 0,000 s OK

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

public class hodnik {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String neki = sc.nextLine();
		char prev = '0';
		int counter = 0;
		for (int i = 0; i < neki.length(); i++) {
			if(neki.charAt(i) == prev){
				counter+=1;
			}
			if (prev == '0'){
				prev = '1';
			} else {
				prev = '0';
			}
		}
		
		char prev1 = '1';
		int counter1 = 0;
		for (int i = 0; i < neki.length(); i++) {
			if(neki.charAt(i) == prev1){
				counter1+=1;
			}
			if (prev1 == '0'){
				prev1 = '1';
			} else {
				prev1 = '0';
			}
		}
		
		//System.out.println(counter + " " + counter1);
		if (counter < counter1){
			System.out.println(counter);
		} else {
			System.out.println(counter1);
		}
		
	
	}

}