Ganesh1648

Subsequence-code2

Jun 14th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. /*package whatever //do not write package name here */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.math.*;
  7.  
  8. class GFG {
  9.    
  10.     static String str;
  11.     static int n;
  12.     static int character(char c)
  13.     {
  14.       if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
  15.         return 1;
  16.       else
  17.         return 0;
  18.     }
  19.     public static void main (String[] args) throws Exception{
  20.        
  21.         BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
  22.         str=bf.readLine();
  23.         StringBuffer s=new StringBuffer("");
  24.         n=str.length();
  25.         int ch[]=new int[n];
  26.         for(int i=0;i<n;i++)
  27.             ch[i]=character(str.charAt(i));
  28.        
  29.         char max=str.charAt(0);    
  30.         for(int i=0;i<n-1;i++)
  31.         {
  32.             if(ch[i]==ch[i+1]){
  33.                if(str.charAt(i+1)>max)
  34.                 max=str.charAt(i+1);
  35.                continue;
  36.             }
  37.             else{
  38.                 s.append(max);
  39.                 max=str.charAt(i+1);
  40.             }
  41.         }
  42.         s.append(max);
  43.         System.out.println(s);
  44.     }
  45. }
Add Comment
Please, Sign In to add comment