반응형

Given two cells on the standard chess board, determine whether they have the same color or not.


Example


For cell1 = "A1" and cell2 = "C3", the output should be

chessBoardCellColor(cell1, cell2) = true.



For cell1 = "A1" and cell2 = "H3", the output should be

chessBoardCellColor(cell1, cell2) = false.



code>>


bool chessBoardCellColor(std::string cell1, std::string cell2) {

return (cell1[0] + cell1[1]) % 2 == (cell2[0] + cell2[1]) % 2;

}

반응형

'알고리즘 > codefights' 카테고리의 다른 글

31>depositProfit  (0) 2017.07.06
30>circleOfNumbers  (0) 2017.07.06
28>alphabeticShift  (0) 2017.07.06
27>variableName  (0) 2017.07.06
26>evenDigitsOnly  (0) 2017.07.06

+ Recent posts