/**
  Scrivere un programma che legge da tastiera una sequenza di 0 e 1, terminata
  da 2, calcola la lunghezza della piu' lunga sottosequenza di 0, e la stampa.

  ESEMPIO: 001010001012 ---> 3
 **/

import java.io.*;

class Sequenza {
  public static void main(String[] args) throws IOException {
      System.out.println("Inserire una sequenza di 0 e 1 terminata da 2");
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      String s = br.readLine();
      int max = 0;     //max num 0 nella seq
      int c = 0;       //cont 0 nella sottoseq corrente
      int i = 0;       //pos stringa sotto analisi
      while(s.charAt(i) != '2') {
	  if (s.charAt(i) == '0') { 
	      c++;
	      if (c > max) max = c;
	  }
	  else /*s.charAt(i) == '1'*/ 
	      c = 0;   // cont 0 resettato
	  i++;
      }
      System.out.println("La sottoseq di 0 piu' lunga ha lunghezza " + max);
  }
}



