C# – Algorithms – Grasshopper And the String – CodeForces.com

Its Friday, the week is finally over and as far as I was planning to write an article per week or so, I have decided to write something. In these cases, when I do not have something prepared, I simply go to codeforces.com and I solve the first or the second problem of the second division. This time I would do the same, although the first problem was extremely easy (probably the easiest one I have ever seen on codeforces) and yet, it is coming.

931fe220d5e33169e0b1bc4f820ecb347277ef29

The idea of the problem is to calculate the maximal jump a grasshopper would have to do, if he wants to jump over the vocals in a string. The only thing you should be careful about is that between his position and the first position he has to jump once, and not zero times. After this, the problem becomes easy – you need two variables  – one for the longest jump so far and one for the current jump. You go through the string and you read the vocals. If the current jump is longer than the longest jump, you update the value of the longest jump. And that’s it.

This is my code, it passed the 60 tests, thus I am not even going to review it:

Enjoy the Friday! 🙂

 

Tagged with: , ,