TopCoder problem "KiloMan" used in SRM 181 (Division II Level One)

Problem Statement


You've reached one of the last bosses in the new hit 2-D side-scrolling action game, KiloMan. The boss has a large gun that can shoot projectiles at various heights. For each shot, KiloMan can either stand still or jump. If he stands still and the shot is at height 1 or 2, then he gets hit. If he jumps and the shot is at a height above 2, then he is also hit. Otherwise, he is not hit. Given the height of each shot and a sequence of jumps, how many hits will KiloMan take?

The input int[] pattern is the pattern of heights at which the shots are being fired. Each element of pattern will be between 1 and 7, inclusive. The input String jumps is the sequence of jumps that KiloMan will attempt; 'J' means he will jump and 'S' means he will stand still. For example, if element 0 of pattern is 3 and character 0 of jumps is 'J', then KiloMan will jump right as a shot is fired at height 3 (and thus he will be hit).

Your method should return an int representing the number of times KiloMan is hit.



Parameters:int[], String
Method signature:int hitsTaken(int[] pattern, String jumps)
(be sure your method is public)


-pattern will contain between 1 and 50 elements, inclusive.
-each number in pattern will be between 1 and 7, inclusive.
-the number of characters in jumps will be the same as the number of elements in pattern
-each character of jumps will be either 'S' or 'J'.


Returns: 4
The first shot is at height 1, and KiloMan jumps it successfully. Then he jumps into a shot at height 3. KiloMan takes three more hits while standing against shots at height 2.
Returns: 49
KiloMan stands still at all the wrong times and jumps at all the wrong times, taking all 49 hits.
Returns: 2
Since everything was shot at height 2 or less, he should have jumped everything.
Returns: 0

Problem url:

Problem stats url:




lbackstrom , schveiguy

Problem categories: