fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. char[]vowel = {'a','e','i','o','u'};
  13. String test = "aeiouaaaeeeiiiooouuu";
  14. int[]dp = new int[5];
  15. int count = 0; // Keeping track of how many identical vowel exist in this block
  16. for(int i = 0; i < test.length(); i++){
  17. int index = -1;
  18. for(int j = 0; j < 5; j++){
  19. if(vowel[j] == test.charAt(i)){
  20. index = j;
  21. break;
  22. }
  23. }
  24. if(index != -1){
  25. if(i > 0 && test.charAt(i - 1) == test.charAt(i)){
  26. count++;
  27. }else{
  28. count = 1;
  29. }
  30. dp[index] = Integer.max(dp[index], count + (index > 0 ? dp[index - 1] : 0));
  31. }
  32. }
  33. System.out.println(dp[4]);
  34.  
  35. }
  36. }
Success #stdin #stdout 0.1s 27828KB
stdin
Standard input is empty
stdout
15