fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define N 5
  4.  
  5. int areaCount(char a[][N + 1], int f, int t)
  6. {
  7. int r = 0, i, j;
  8.  
  9. for (i = f / N; i <= t / N ; ++i) {
  10. for (j = f % N; j <= t % N ; ++j) {
  11. if (a[i][j] == '1')++r;
  12. else return 0;
  13. }
  14. }
  15.  
  16. return r;
  17. }
  18.  
  19. void func(char a[][N + 1])
  20. {
  21. int f, t, w, max = 0;
  22.  
  23. for (f = 0; f < N * N; ++f) {
  24. for (t = f + 1; t < N * N; ++t) {
  25. w = areaCount(a, f, t);
  26. if (max < w)max = w;
  27. }
  28. }
  29. printf("%d\n", max);
  30. }
  31.  
  32. int main()
  33. {
  34. char buf[100], a[N][N + 1];
  35.  
  36. fgets(buf, 100, stdin);
  37. int n = atoi(buf);
  38. while (n--) {
  39. {
  40. int i = 0;
  41. while (fgets(buf, 100, stdin)) {
  42. if (buf[0] == '\n')break;
  43. sprintf(a[i++], "%s", buf);
  44. }
  45. func(a);
  46. }
  47. }
  48.  
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0s 1792KB
stdin
3
11010
01111
10101
01110
01100

01011
01010
00100
00110
10100

11110
01110
01101
01110
00001
stdout
4
3
8