簡単 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 つずつ開いてみましょう。

ヒント 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用に調整されています。上記の説明と制約に従ってください。

ランキング

全体ランキング

コーダーごとのいちばん良い合格解答です。速く、メモリが少なく、評価が高い解答ほど上位になります。

まだ合格した解答はありません。解いて 1 位になりましょう。

他の人の解答から学ぶ

コミュニティの解答

まだ公開された解答がありません。この課題を解いて最初の解答を共有しましょう。