fork(1) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Main {
  6. public static void main (String[] args) {
  7. int n;
  8. Scanner scan = new Scanner(System.in);
  9. n = scan.nextInt();
  10. scan.nextLine();
  11. for (int i = 0; i < n; i++) {
  12. String x = scan.nextLine();
  13. int count = 0;
  14. int from = -1;
  15. while ((from = x.indexOf('1', from + 1)) >= 0) {
  16. count += (from / 2 == i)? 2 : 1;
  17. }
  18. System.out.print(count + " ");
  19. }
  20. }
  21. }
Success #stdin #stdout 0.16s 321344KB
stdin
5
0 1 1 1 1
1 0 0 0 0
0 1 1 1 0
0 0 0 0 1
1 1 1 1 0
stdout
4 1 4 1 4