Statistics

Problem Statement for "Shaky"

Problem Statement

Class Name: Shaky
Method Name: isShaky
Parameters: int
Returns: int

TopCoder has made up a term to describe a certain type of number.  We call it a
"shaky" number.  You can determine if a number is shaky according to the
following rules:
(1) starting from the left-most digit and moving right, a pattern must be
followed of "greater than", "less than", "greater than", "less than", etc. For
example, 465768 is considered shaky because
   6 is greater than 4,
   5 is less than 6
   7 is greater then 5
   6 is less than 7
   8 is greater than 6
(2) any single digit number IS considered shaky.
(3) The first comparison may be "greater than" or "less than", and alternate
after that. It does not necessarily need to end with a "greater than" or "less
than".

Implement a class Shaky that contains a method isShaky. The method takes an int
as a parameter and returns 1 if the int is shaky and 0 otherwise.

Here is the method signature:
public: int isShaky(int in);

in is positive and less than 1000000.

EXAMPLES:
5252 - should return 1
2525 - should return 1
25 - should return 1
52 - should return 1
8 - should return 1
33 - should return 0
521 - should return 0
23234 - should return 0

Definition

Class:
Shaky
Method:
isShaky
Parameters:
int
Returns:
int
Method signature:
int isShaky(int param0)
(be sure your method is public)

Constraints

    Examples


      This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
      This problem was used for: