Camel Case 4

  • + 0 comments
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
            Scanner input = new Scanner(System.in);
            while(input.hasNextLine()){
                String next = input.nextLine();
                char operation = next.charAt(0);
                char type = next.charAt(2);
                String item = next.substring(4);
                if(operation=='S'){
                    String result = new String();
                    for(char i : item.toCharArray()){
                        if(type=='M'&& i=='('){
                            break;
                        }
                        if(result.isEmpty()==false && Character.isUpperCase(i)){
                            result+=' ';
                        }
                        result+=Character.toLowerCase(i);
                    }
                    System.out.println(result);
                }
                if(operation=='C'){
                    String result = new String();
                    int flag = 0 ;
                    for(char i : item.toCharArray()){
                        if(result.isEmpty()){
                            if(type=='C'){
                                result+=Character.toUpperCase(i);
                                continue;
                            }  
                        }
                        if(flag!=1 && i!=' '){
                            result+=i;
                        }
                        if(flag == 1){
                            result+=Character.toUpperCase(i);
                            flag = 0;
                        }
                        if(i==' '){
                            flag = 1;
                            continue;
                        }
                    }
                    if(type=='M'){
                        result+="()";
                    }
                    System.out.println(result);
                }
            }
        }
    }