Easy

Consider integer numbers from 0 to n - 1 written down along the circle in such a way that the distance between any two neighboring numbers is equal (note that 0 and n - 1 are neighboring, too).

Given n and firstNumber, find the number which is written in the radially opposite position to firstNumber.

Example

For n = 10 and firstNumber = 2, the output should be
circleOfNumbers(n, firstNumber) = 7.

Input/Output

  • [execution time limit] 0.5 seconds (c)

  • [input] integer n

    A positive even integer.

    Guaranteed constraints:
    4 ≤ n ≤ 20.

  • [input] integer firstNumber

    Guaranteed constraints:
    0 ≤ firstNumber ≤ n - 1.

  • [output] integer

[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

int circleOfNumbers(int n,int firstNumber)
{
	return firstNumber+n/2>=n?firstNumber-n/2:firstNumber+n/2;
}
728x90

'Codesignal' 카테고리의 다른 글

<Codesignal> absoluteValuesSumMinimization  (0) 2020.04.05
<Codesignal> depositProfit  (0) 2020.04.05
<Codesignal> chessBoardCellColor  (0) 2020.04.05
<Codesignal> alphabeticShift  (0) 2020.04.05
<Codesignal> variableName  (0) 2020.04.05

+ Recent posts