Camel Case 4

  • + 0 comments

    Working code in python:

    # Enter your code here. Read input from STDIN. Print output to STDOUT
    import sys
    import re
    
    def caseChange(input_lines): 
        lines = input_lines.strip().split("\n")
        
        for line in lines: 
            operation, var_type, words = line.split(";")
            #print(f"INPUT: {line}")
            #print(f"Operation:{operation}, Variable: {var_type}, Words:{words}")
        
            #split -- camel case to space-delimited list of words
            if operation == "S":
                words = re.sub(r'([a-z])([A-Z])', r'\1 \2', words).lower()
                output = words
              
                if var_type == "M":
                    words = words.rstrip("()")
                    output = words
                
                print(output)
        
            
        #combine -- space-delimited to camelCase
            elif operation == "C":
                split_words = words.split()
                
                if var_type == "C":
                    output = ''.join(word.capitalize() for word in split_words)
                    
                else: 
                    output = split_words[0].lower() + "".join(word.capitalize() for word in split_words[1:])
                
                if var_type == "M":
                    output += "()"
                
                print(output)
    
            
    if __name__ == "__main__":
        for line in sys.stdin:
            caseChange(line.strip("\r\n"))