Easy
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.
Input/Output
-
[execution time limit] 0.5 seconds (c)
-
[input] string cell1
Guaranteed constraints:
cell1.length = 2,
'A' ≤ cell1[0] ≤ 'H',
1 ≤ cell1[1] ≤ 8. -
[input] string cell2
Guaranteed constraints:
cell2.length = 2,
'A' ≤ cell2[0] ≤ 'H',
1 ≤ cell2[1] ≤ 8. -
[output] boolean
- true if both cells have the same color, false otherwise.
[C] Syntax Tips
// Prints help message to the console
// Returns a string
char * helloWorld(char * name) {
char * answer = malloc(strlen(name) + 8);
printf("This prints to the console when you Run Tests");
strcpy(answer, "Hello, ");
strcat(answer, name);
return answer;
}
더보기
Solution
bool chessBoardCellColor(char *cell1,char *cell2)
{
return abs(cell1[0]-cell2[0])%2==abs(cell1[1]-cell2[1])%2;
}
728x90
'Codesignal' 카테고리의 다른 글
<Codesignal> depositProfit (0) | 2020.04.05 |
---|---|
<Codesignal> Circle of Numbers (0) | 2020.04.05 |
<Codesignal> alphabeticShift (0) | 2020.04.05 |
<Codesignal> variableName (0) | 2020.04.05 |
<Codesignal> evenDigitsOnly (0) | 2020.04.05 |