The following code seeks to determine if an array of size N, composed of "." and "#" can be split in two, such that the number of characters "#" in each piece is the same. The partition must be done horizontally or vertically, it can not be diagonal or zigzag. If this can be done, return "YES" otherwise "No". The input consists of a number T that will be the number of cases to be evaluated, the number N that is the size of the matrix and finally the matrix. For example:
This was the solution attempt
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int T, N, ca = 0, fa = 0, cd, fd, l, j, k, i;
bool oso = 0;
cin >> T;
for (i = 0; i < T; ++i) {
cin >> N;
char cho[N][N];
for (int i = 0; i < N; i++)
scanf("%s", cho[i]);
int col[N] = { 0 };
int fil[N] = { 0 };
for (k = 0; k < N; ++k) {
for (j = 0; j < N; ++j) {
if ((cho[k][j] == '#') && (cho[j][k] == '#')) {
col[j] += 1;
fil[j] += 1;
} else if (cho[j][k] == '#') {
fil[j] += 1;
} else if (cho[k][j] == '#') {
col[j] += 1;
}
}
}
for (j = 1; j < N; ++j) {
cd = 0;
fd = 0;
ca += col[j - 1];
fa += fil[j - 1];
for (l = N - 1; l >= j; --l) {
cd += col[l];
fd += fil[l];
}
if ((ca == cd) || (fa == fd)) {
oso = 1;
break;
}
}
if (oso == 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
However, I notice that the code does not detect cases where it does not work. What part of the code could be failing, what do you recommend?