Skip to content

Conversation

@vitalykom
Copy link

No description provided.

@KFalcon2022 KFalcon2022 self-assigned this Feb 4, 2025
return "";
}
int[][] matrixLengthCount = new int[n + 1][2];
int[][] matrix = new int[n][n];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Использование массивов в этой задаче - чит. Предлагаю попробовать без них:)

if (k == 1) {
spaceCount++;
} else {
int temp = ((matrixLengthCount[k][0] - matrixLengthCount[k - 1][0]) - (matrixLengthCount[k - 1][0] - matrixLengthCount[k - 2][0])) / 2;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Строка кода должна быть ограничена 120 символами. Считается, что именно столько влазит в один экран при стандартных настройках. В IDE обычно даже вертикальная линия есть, отмечающая это значение в рабочей зоне

builder.insert(matrixLengthCount[i - 1][0], ' ');
}
}
return builder.toString();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Задача фактически не решена. Результаты тестов:
image
image

return getNum(rows - 1, cols - 1) + getNum(rows - 1, cols);
}
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Файл должен завершаться пустой строкой https://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline

maxLength = temp.length() - 1;

for (int i = 0; i < rows; i++) {
temp.delete(0, temp.length());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Удаление всей строки?) зачем? Не проще новую строку создать? Да и в целом логичнее в новую переменную вынести

temp.append(getNum(i, j)).append(" ");
}
temp.deleteCharAt(temp.length() - 1);
result.append(" ".repeat(Math.max(0, (maxLength - temp.length()) / 2))).append(temp).append('\n');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Math.max(0, (maxLength - temp.length()) / 2) - в переменную с понятным названием.
Кроме того, епочки вызовов лучше оформлять по правилу точка-строчка - каждый новый верхнеуровневый вызов с новой строки. Читается лучше, в более старых версиях джавы (кажется, до 17) облегчит локализацию NullPointerException:

int shift = Math.max(0, (maxLength - temp.length()) / 2); //здесь у тебя еще скобки лишние в вычитании

result.append(" ".repeat(shift))
    .append(temp)
    .append('\n');

return getNum(rows - 1, cols - 1) + getNum(rows - 1, cols);
}
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В целом, стало намного лучше

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants