Trang

Thứ Bảy, 1 tháng 1, 2011

1090. City Hall

http://acm.tju.edu.cn/toj/showp1090.html

import java.io.*; import java.util.Arrays; public class Main { /** * @author hunglee */ static BufferedReader bin = new BufferedReader( new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { int m = 0, n = 0; m = readInt(); n = readInt(); int a[][] = new int[m + 1][n]; String s; for (int i = 0; i < m; ++i) { do { s = bin.readLine(); } while (s.length() != n); for (int j = 0; j < n; ++j) a[i][j] = s.charAt(j) - '0'; } Arrays.fill(a[m], 1); int h[] = new int[m + 1]; int l; for (int j = 0; j < n; ++j) { l = 0; for (int i = 0; i <= m; ++i) if (a[i][j] == 0) ++l; else { ++h[l]; l = 0; } } for (int i = 1; i <= m; ++i) if (h[i] > 0) System.out.println(i + " " + h[i]); } private static int readInt() throws IOException { int res = 0, i; do { i = bin.read(); if (i < '0' || i > '9') break; res = 10 * res + i - '0'; } while (true); return res; } }

Không có nhận xét nào:

Đăng nhận xét