반응형
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. |
code>>
bool isInfiniteProcess(int a, int b) {
return ((a - b) & 1) || a > b;
}
반응형
'알고리즘 > codefights' 카테고리의 다른 글
14>tennisSet (0) | 2019.02.24 |
---|---|
13>arithmeticExpression (0) | 2018.05.20 |
11>extraNumber (0) | 2018.05.19 |
10>knapsackLight (0) | 2018.05.19 |
9>reachNextLevel (0) | 2018.05.19 |