You are on page 1of 2

Bài

W02H03 – if/else
Code thầy cho trước:

Đề bài:

Since there are of course both female and male penguins, we would like to differentiate between
them. Luckily, this is very easy, because while male penguins are always even-numbered, female
penguins can be clearly identified as odd-number.

Implement the penguEvolution(int, int) method. The penguin in this task must be penguin>0. Every
year, a penguin changes according to the following rules. Because penguin males are always stressed
and complain so much, male penguins halve their numbers. Particularly stressed male penguins are
powers of two (2 " , x∈N\{0}). Instead of just halving, these become 1. Female penguins, on the other
hand, are so cheerful and dance so much that they tripple their number and add 1 to it. For traditional
reasons, the female penguins are happiest when they are a multiple of 7, so they remain in that state
for exactly 7 years before continuing their evolution. Note that this could cause the penguins from our
particular colony to change sex from year to year. The method should return the state/number of the
given penguin after the given number of years. In the examples, the parameters are always given after
"IN: ", the return value that should be calculated for these parameters after "OUT: ", and the entire
evolution over the transferred period after "EVO: ". The evolution is included for clarity and should not
be given separately. The correct return value is enough.

Ví Dụ:

You might also like