Easy

Given integers a and b, determine whether the following pseudocode results in an infinite loop

while a is not equal to b do

       increase a by 1                  

       decrease b by 1                 

Assume that the program is executed on a virtual machine which can store arbitrary long numbers and execute forever.

Example

  • For a = 2 and b = 6, the output should be
    isInfiniteProcess(a, b) = false;
  • For a = 2 and b = 3, the output should be
    isInfiniteProcess(a, b) = true.

Input/Output

  • [execution time limit] 0.5 seconds (c)

  • [input] integer a

    Guaranteed constraints:
    0 ≤ a ≤ 20.

  • [input] integer b

    Guaranteed constraints:
    0 ≤ b ≤ 20.

  • [output] boolean

    • true if the pseudocode will never stop, 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 isInfiniteProcess(int a,int b)
{
	return a>b||abs(a-b)%2==1;
}
728x90

'Codesignal' 카테고리의 다른 글

<Codesignal> Tennis Set  (0) 2020.04.07
<Codesignal> Arithmetic Expression  (0) 2020.04.07
<Codesignal> Extra Number  (0) 2020.04.07
<Codesignal> Reach Next Level  (0) 2020.04.07
<Codesignal> Phone Call  (0) 2020.04.07

+ Recent posts