Rezultati

Up. imeNalogaJezikRezultatČas oddaje
snajper Niz Java 100/100OK 19. apr '18 @ 16:36

Test Točke Porabljen spomin Porabljen čas Status
#1 10/10 40,078 MiB 0,000 s OK
#2 10/10 37,629 MiB 0,000 s OK
#3 10/10 39,910 MiB 0,000 s OK
#4 10/10 40,367 MiB 0,000 s OK
#5 10/10 44,719 MiB 0,000 s OK
#6 10/10 42,379 MiB 0,000 s OK
#7 10/10 39,941 MiB 0,000 s OK
#8 10/10 39,664 MiB 0,000 s OK
#9 10/10 40,281 MiB 0,000 s OK
#10 10/10 44,586 MiB 0,000 s OK

Ocenjevani program (Niz.java):
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

/**
 * Created by snajper on 4/19/18.
 */
public class Niz {
    public static void main(final String[] args) {

        Scanner in = new Scanner(System.in);
        /*try {
            in = new Scanner(new File("./niz/00.in"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }*/

        final int n = in.nextInt();
        in.nextLine();
        final String line = in.nextLine();
        final char[] chars = line.toCharArray();

        int counter = 0;
        for (int i = 2; i < n; i++) {
            //line.substring(i-2, )
            /*if (line.charAt(i-2) == '0' && line.charAt(i-1) == '1' && line.charAt(i) == '0') {
                line =
            }*/
            if (chars[i-2] == '0' && chars[i-1] == '1' && chars[i] == '0') {
                chars[i] = '1';
                counter++;
            }
        }

        System.out.println(counter);
    }
}