Rezultati

Up. imeNalogaJezikRezultatČas oddaje
pridnerozice-2018 Niz Java 100/100OK 19. apr '18 @ 16:46

Test Točke Porabljen spomin Porabljen čas Status
#1 10/10 35,832 MiB 0,000 s OK
#2 10/10 37,063 MiB 0,000 s OK
#3 10/10 39,824 MiB 0,000 s OK
#4 10/10 39,813 MiB 0,000 s OK
#5 10/10 40,590 MiB 0,000 s OK
#6 10/10 43,199 MiB 0,000 s OK
#7 10/10 41,043 MiB 0,000 s OK
#8 10/10 39,520 MiB 0,000 s OK
#9 10/10 40,105 MiB 0,000 s OK
#10 10/10 43,484 MiB 0,000 s OK

Ocenjevani program (Niz.java):
import java.util.*;

class Niz{
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String niz = sc.next();
        int st = 0;
        int spremembe = 0;
        boolean nic = false;
        boolean ena = false;
        while(st < n){
            char trenutni = niz.charAt(st);
            if(nic && ena){
                if(trenutni=='0') {
                    spremembe++;
                }
                nic = false;
                ena = false;
            }
            else if (nic){
                if(trenutni=='1'){
                    ena = true;
                }
            }
            else{
                if(trenutni=='0'){
                    nic = true;
                }
            }
            st++;
        }
        System.out.println(spremembe);

    }
}