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.
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
using System; using System.Collections.Generic; class Problem1_378 { static void Main() { string str_first = Console.ReadLine(); List<Char> my_vocals = new List<Char> { 'A', 'E', 'I', 'O', 'U','Y'}; long l_result = 0; long l_current = 0; foreach (char my_char in str_first) { if (my_vocals.Contains(my_char)) { if (l_current > l_result) { l_result = l_current; } l_current = 0; } else { l_current++; } } if (l_current > l_result) { l_result = l_current; } Console.WriteLine(l_result+1); } } |
Enjoy the Friday! 🙂