We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
# Enter your code here. Read input from STDIN. Print output to STDOUTimportsysimportredefcaseChange(input_lines):lines=input_lines.strip().split("\n")forlineinlines: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 wordsifoperation=="S":words=re.sub(r'([a-z])([A-Z])',r'\1\2',words).lower()output=wordsifvar_type=="M":words=words.rstrip("()")output=wordsprint(output)#combine -- space-delimited to camelCaseelifoperation=="C":split_words=words.split()ifvar_type=="C":output=''.join(word.capitalize()forwordinsplit_words)else:output=split_words[0].lower()+"".join(word.capitalize()forwordinsplit_words[1:])ifvar_type=="M":output+="()"print(output)if__name__=="__main__":forlineinsys.stdin:caseChange(line.strip("\r\n"))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Camel Case 4
You are viewing a single comment's thread. Return to all comments →
Working code in python: