Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- import java.io.*;
- import java.math.*;
- /* Name of the class has to be "Main" only if the class is public. */
- class Codechef {
- static String str;
- static int max_len=0;
- static int max_sum=0;
- static String res="";
- static int character(char c)
- {
- if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
- return 1;
- else
- return 0;
- }
- static void solve(int cur,int prev,int len,int sum,String st) {
- if(cur>=str.length())
- {
- if(max_len<len)
- {
- max_sum=sum;
- max_len=len;
- res=st;
- }
- else if(max_len==len)
- {
- if(max_sum<sum){
- max_sum=sum;
- res=st;
- }
- }
- return;
- }
- if(prev==-1)
- {
- solve(cur+1,cur,len+1,sum+str.charAt(cur)-'a',st+""+str.charAt(cur));
- solve(cur+1,prev,len,sum,st);
- }
- else if(character(str.charAt(prev))!=character(str.charAt(cur)))
- {
- solve(cur+1,cur,len+1,sum+str.charAt(cur)-'a',st+""+str.charAt(cur));
- solve(cur+1,prev,len,sum,st);
- }
- else
- solve(cur+1,prev,len,sum,st);
- }
- public static void main(String[] args) throws java.lang.Exception {
- BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
- str=bf.readLine();
- solve(0,-1,0,0,"");
- System.out.println(res);
- }
- }
Add Comment
Please, Sign In to add comment