Легко Решено: 0 Процент решений: 0%

Chess Square Color

Determine the color of a square on an 8 by 8 board.

Чему вы научитесь

  • Turn a square name into row and column numbers
  • Use parity to decide the color
  • Convert letters to numbers

Условие

Показать перевод

Use a board whose top-left square is white. Rows and columns start at 0 at the top left. Adjacent squares alternate colors. Return empty text for a position outside the board.

Implement chess_square_color(column, row).

Input

column: The column, counted from the left starting at 0.

row: The row, counted from the top starting at 0.

Output

Return white, black, or an empty string for invalid coordinates.

Ограничения

−10 ≤ column, row ≤ 20. Valid board coordinates are 0 through 7.

Примеры

Пример 1
Ввод:
column = 2
row = 3

Ожидаемый вывод:
expected = "black"
Ввод:
long long column = 2;
long long row = 3;

Ожидаемый вывод:
std::string expected = "black";
Ввод:
long column = 2;
long row = 3;

Ожидаемый вывод:
string expected = "black";

Пояснение

Five steps from the white corner change color an odd number of times.

Пример 2
Ввод:
column = 8
row = 0

Ожидаемый вывод:
expected = ""
Ввод:
long long column = 8;
long long row = 0;

Ожидаемый вывод:
std::string expected = "";
Ввод:
long column = 8;
long row = 0;

Ожидаемый вывод:
string expected = "";

Пояснение

Column 8 is outside the valid range 0 through 7.

Как подступиться

Сначала попробуйте сами, затем открывайте подсказки по одной.

Подсказка 1

Square color alternates with moves across rows and columns, so only the coordinate pattern matters.

Подсказка 2

A parity check on row and column can tell you which color to return.

Подсказка 3

Return empty text immediately when either coordinate is outside the 0 to 7 board range.

Ожидаемая сложность

O(1) time, O(1) extra space

Ссылки

Это задание адаптировано для CodeUtility. Следуйте условию и ограничениям выше.

Лучшее принятое решение каждого участника. Более быстрые, экономные и высоко оценённые решения стоят выше.

Принятых решений пока нет. Решите задачу и займите первое место.

Учитесь у других

Решения сообщества

Пока нет опубликованных решений. Решите задание, чтобы поделиться первым.