fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int n;
  5. scanf("%d", &n);
  6.  
  7. int row_has[100] = {0};
  8. int col_has[100] = {0};
  9. char c;
  10.  
  11. for (int i = 0; i < n; i++) {
  12. for (int j = 0; j < n; j++) {
  13. scanf(" %c", &c);
  14. if (c == '#') {
  15. row_has[i] = 1;
  16. col_has[j] = 1;
  17. }
  18. }
  19. }
  20.  
  21. int row_need = 0, col_need = 0;
  22. for (int i = 0; i < n; i++) row_need += row_has[i];
  23. for (int j = 0; j < n; j++) col_need += col_has[j];
  24.  
  25. int ans = (row_need < col_need ? row_need : col_need);
  26. printf("%d\n", ans);
  27.  
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0s 5316KB
stdin
4
.#.#
.##.
....
##..
stdout
3