SRM 643, D2, 250-Pointer (TheKingsArmyDiv2)
James S. Plank
Wed Jan 18 13:56:49 EST 2017
Give this one a try, and if you want help, then read below.
From the example in the writeup, if there are two adjacent H's, either horizonally or vertically, then the whole
army will eventually be happy. So, the King's goal is to make sure that there are two adjacent happy soldiers.
This means that there are only three cases to care about:
Your program simply needs to test for these cases. I would advise doing four things in this order.
- If there are two adjacent H's, return 0.
- Otherwise, if there is an H anywhere, return 1, because the king can simply place an H adjacent to one that's
- If there are no H's, then return 2, because the king needs to place two H's next to each other.
- Look to make sure that at least one string has an H. If not, return 2. I used a for
loop and the find() method of strings to do this part.
- Now, look to see if there is an "HH" in any string. Again, you can use a for loop and
the find() method of strings. If you find an "HH", then return 0.
- Look for two H's that are adjacent vertically. This requires a double for loop. If you find
two H's that are adjacent vertically, return 0.
- If you've reached this point, then there is at least one H, but no adjacent H's. Return 1.