fix printBoards
This commit is contained in:
parent
5bfef3f9dd
commit
e3a728e10b
30
main.cpp
30
main.cpp
@ -213,31 +213,32 @@ void deallocBoard(char **board, int x) {
|
||||
void printBoard(char **board, int x, int y) {
|
||||
int boardX = x + 2;
|
||||
int boardY = y + 2;
|
||||
myVec<myVec<char> > ans(boardX);
|
||||
myVec<myVec<string> > ans(boardX);
|
||||
|
||||
for (int i = 0; i < boardX; ++i) {
|
||||
ans[i] = myVec<string>(boardY);
|
||||
for (int j = 0; j < boardY; ++j) {
|
||||
ans[i].push_back(' ');
|
||||
ans[i][j] = " ";
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < y; ++i) {
|
||||
if (!(i % 10)) {
|
||||
ans[0][i] = (i / 10) + '0';
|
||||
ans[0][i] = toString((i / 10));
|
||||
}
|
||||
ans[1][i] = (i % 10) + '0';
|
||||
ans[1][i] = toString((i % 10));
|
||||
}
|
||||
|
||||
for (int i = 0; i < x; ++i) {
|
||||
if (!(i % 10)) {
|
||||
ans[i + 2][0] = (i / 10) + '0';
|
||||
ans[i + 2][0] = toString((i / 10));
|
||||
}
|
||||
ans[i + 2][1] = (i % 10) + '0';
|
||||
ans[i + 2][1] = toString((i % 10));
|
||||
}
|
||||
|
||||
for (int i = 0; i < x; ++i) {
|
||||
for (int j = 0; j < y; ++j) {
|
||||
ans[i + 2][j + 2] = board[i][j];
|
||||
ans[i + 2][j + 2] = string(1, board[i][j]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -245,9 +246,12 @@ void printBoard(char **board, int x, int y) {
|
||||
int maxLength = 0;
|
||||
for (int i = 0; i < x; ++i) {
|
||||
int length = 2 + (i >= 10 ? 2 : 1);
|
||||
if (length > maxLength) {
|
||||
maxLength = length;
|
||||
}
|
||||
for(int j = 0; j < y; ++j) {
|
||||
if (ans[i + 2][j + 2].size() > length) {
|
||||
length = ans[i + 2][j + 2].size();
|
||||
}
|
||||
}
|
||||
maxLength = max(maxLength, length);
|
||||
}
|
||||
|
||||
// Print the first two rows with the calculated spaces
|
||||
@ -264,14 +268,12 @@ void printBoard(char **board, int x, int y) {
|
||||
// Print the rest of the board
|
||||
for (int i = 2; i < boardX; ++i) {
|
||||
for (int j = 0; j < boardY; ++j) {
|
||||
if (j == 2) {
|
||||
if (j==2) {
|
||||
pt ' ';
|
||||
}
|
||||
pt ans[i][j];
|
||||
if (j == boardY - 1) {
|
||||
pt nl;
|
||||
}
|
||||
}
|
||||
pt nl;
|
||||
}
|
||||
pt endl;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user