Problem:


Problem P04: CamelCase

プログラミングにおける識別子（変数や関数）の命名では、
単語を連結した複合語が使われる。
しかし、そのまま連結すると単語の区切りがわからなくなるため、
一般的に以下の命名規則の中から統一するものを選び適用する：

Upper CamelCase　にする

単語を直接連結し複合語とし、各単語の先頭文字のみを大文字にする。

例： GetUserName

Lower CamelCase　にする

単語を直接連結し複合語とし、各単語の先頭文字のみを大文字にする。ただし、複合語の先頭文字は小文字にする。

例： getUserName

アンダースコアで繋ぐ

単語をアンダースコアで連結し複合語とする。単語の文字はすべて小文字にする。

例： get_user_name

与えられた識別子を、指定された命名規則を適用して出力するプログラムを作成せよ。
与えられる識別子は、上記の命名規則のいづれかが既に適用されているものとする。

Input

入力として複数のデータセットが与えられる。各データセットは以下の形式で与えられる：

name type （識別子、命名規則：　空白区切りの文字列と文字）

typeは命名規則を示す文字であり、以下の表の通りとする：

type命名規則

UUpper CamelCase にする

LLower CamelCase にする

Dアンダースコアで繋ぐ

与えられる識別子の文字数は 1 以上 100 以下である。

type が 'X' のとき入力の終わりとする。この入力に対する出力を行ってはならない。

Output

各データセットについて、命名規則を適用した識別子を1行に出力せよ。

Sample Input

get_user_name L
getUserName U
GetUserName D
EndOfInput X

Output for the Sample Input

getUserName
GetUserName
get_user_name



Sample input:
get_user_name L
getUserName U
GetUserName D
EndOfInput X


Sample output:
getUserName
GetUserName
get_user_name

Submission status: Wrong Answer

Solution code:
while True:
    name,type = map(str, raw_input().split())
    ans = ""
    if (type == 'X'):
        break
    names = []
    if (name.find("_") != -1):
        names = name.split("_")
    elif (name[0].islower() == True):
        tmp = name[0]
        for i in range(1, len(name)):
            if (name[i].isupper() == True):
                names.append(tmp)
                tmp = name[i]
            else:
                tmp += name[i]
        if (len(tmp) > 1):
            names.append(tmp)
    else:
        tmp = name[0]
        for i in range(1, len(name)):
            if (name[i].isupper() == True):
                names.append(tmp)
                tmp = name[i]
            else:
                tmp += name[i]
        if (len(tmp) > 1):
            names.append(tmp)
    if (type == "U"):
        for x in names:
            ans += x[0].upper()
            ans += x[1:].lower()
    elif (type == "L"):
        cnt = 0
        for x in names:
            if (cnt == 0):
                ans += x.lower()
            else:
                ans += x[0].upper()
                ans += x[1:].lower()
            cnt += 1
    else:
        ans = "_".join(names)
        ans = ans.lower()
    print ans

Submission status: Wrong Answer

Solution code:
import re
while True:
    c, t = input().split()
    if t == "X":
        break
    if t == "U":
        if "_" in c:
            tmp = c.split("_")
            hoge = ""
            for t in tmp:
                hoge += t[0].upper() + t[1:]
            c = hoge
        else:
            c = c[0].upper() + c[1:]
    elif t == "L":
        if "_" in c:
            tmp = c.split("_")
            flag = True if len(tmp) > 1 else False
            hoge = ""
            for t in tmp:
                hoge += t[0].upper() + t[1:]
            if flag:
                hoge = hoge[0].lower() + hoge[1:]
            c = hoge
        else:
            if re.match('[A-Z]', c):
                c = c[0].lower() + c[1:]
            else:
                c = c[0].upper() + c[1:]
    else:
        tmp = re.findall('[a-zA-Z][a-z]+', c)
        hoge = ""
        for t in tmp:
            hoge += t[0].lower() + t[1:] + "_"
        c = hoge[:-1]
    print(c)

Submission status: Wrong Answer

Solution code:
import re
while True:
    c, t = input().split()
    if t == "X":
        break
    if t == "U":
        if "_" in c:
            tmp = c.split("_")
            hoge = ""
            for t in tmp:
                hoge += t[0].upper() + t[1:]
            c = hoge
        else:
            c = c[0].upper() + c[1:]
    elif t == "L":
        if "_" in c:
            tmp = c.split("_")
            flag = True if len(tmp) > 1 else False
            hoge = ""
            for t in tmp:
                hoge += t[0].upper() + t[1:]
            if flag:
                hoge = hoge[0].lower() + hoge[1:]
            c = hoge
        else:
            c = c[0].lower() + c[1:]
    else:
        tmp = re.findall('[a-zA-Z][a-z]+', c)
        hoge = ""
        for t in tmp:
            hoge += t[0].lower() + t[1:] + "_"
        c = hoge[:-1]
    print(c)

Submission status: Wrong Answer

Solution code:
while True:
    name,typ=raw_input().split()
    if name=="EndOfInput" and typ=="X":break
    L=[]
    if "_" in name:
        L=name.split("_")
    elif  name[0].islower():
        temp=""
        for ch in name:
            if ch.islower():
                temp+=ch
            else:
                L.append(temp)
                temp=""
                temp+=ch
        L.append(temp)
    else:
        temp=name[0]
        for ch in name[1:]:
            if ch.islower():
                temp+=ch
            else:
                L.append(temp)
                temp=""
                temp+=ch
        L.append(temp)

    if typ=="D":
        print "_".join(map(lambda s:s.lower(),L))
    elif typ=="U":
        print "".join(map(lambda s:s.capitalize(),L))
    else:
        print L[0]+"".join(map(lambda s:s.capitalize(),L[1:]))

Submission status: Wrong Answer

Solution code:
import re
while True:
    name,typ=raw_input().split()
    if name=="EndOfInput" and typ=="X":break
    if "_" in name:
        L=name.split("_")
    else:
        L=re.findall("[A-Z][a-z]*",name[0].upper()+name[1:])

    if typ=="D":
        print "_".join(map(lambda s:s.lower(),L))
    elif typ=="U":
        print "".join(map(lambda s:s.capitalize(),L))
    else:
        print L[0]+"".join(map(lambda s:s.capitalize(),L[1:]))

Submission status: Wrong Answer

Solution code:
while 1:
	a,type = raw_input().split()
	if type == "X": break
	ans = ""
	if type == "U":
		for word in a.split("_"):
			ans += word.capitalize()
	elif type == "L":
		for word in a.split("_"):
			ans += word.capitalize()
		ans = ans[0].lower() + ans[1:]
	else:
		if "_" not in a:
			words = []
			sp = 0
			for i in range(1,len(a)):
				if a[i].isupper() :
					words.append(a[sp:i].lower())
					sp = i
			words.append(a[sp:].lower())
			ans = "_".join(words)
		else:
			ans = a
	print ans

Submission status: Wrong Answer

Solution code:
while 1:
	a,type = raw_input().split()
	if type == "X": break
	ans = ""
	if type == "U":
		for word in a.split("_"):
			ans += word[0].upper() + word[1:]
	elif type == "L":
		for word in a.split("_"):
			ans += word.capitalize()
		ans = ans[0].lower() + ans[1:]
	else:
		if "_" not in a:
			words = []
			sp = 0
			for i in range(1,len(a)):
				if a[i].isupper() :
					words.append(a[sp:i].lower())
					sp = i
			words.append(a[sp:].lower())
			ans = "_".join(words)
		else:
			ans = a
	print ans

Submission status: Accepted

Solution code:
# AOJ 1044: CamelCase
# Python3 2018.7.6 bal4u

while True:
	n, t = input().split()
	if t == 'X': break
	ans, n = '', list(n)
	if t == 'U':
		ans += n.pop(0).upper()
		while n != []:
			while n != [] and n[0] != '_': ans += n.pop(0)
			if len(n) > 1 and n[0] == '_':
				del n[0]
				ans += n.pop(0).upper()
	elif t == 'L':
		ans += n.pop(0).lower()
		while n != []:
			while n != [] and n[0] != '_': ans += n.pop(0)
			if len(n) > 1 and n[0] == '_':
				del n[0]
				ans += n.pop(0).upper()
	else:
		ans += n.pop(0).lower()
		while n != []:
			while n != [] and n[0].isupper() == False: ans += n.pop(0)
			if n != [] and n[0].isupper(): ans += '_' + n.pop(0).lower()
	print(ans)

Submission status: Accepted

Solution code:
while True:
    name,type = map(str, raw_input().split())
    ans = ""
    if (type == 'X'):
        break
    names = []
    if (name.find("_") != -1):
        names = name.split("_")
    elif (name[0].islower() == True):
        tmp = name[0]
        for i in range(1, len(name)):
            if (name[i].isupper() == True):
                names.append(tmp)
                tmp = name[i]
            else:
                tmp += name[i]
        if (len(tmp) > 0):
            names.append(tmp)
    else:
        tmp = name[0]
        for i in range(1, len(name)):
            if (name[i].isupper() == True):
                names.append(tmp)
                tmp = name[i]
            else:
                tmp += name[i]
        if (len(tmp) > 0):
            names.append(tmp)
    # print names
    if (type == "U"):
        for x in names:
            ans += x[0].upper()
            ans += x[1:].lower()
    elif (type == "L"):
        cnt = 0
        for x in names:
            if (cnt == 0):
                ans += x.lower()
            else:
                ans += x[0].upper()
                ans += x[1:].lower()
            cnt += 1
    else:
        ans = "_".join(names)
        ans = ans.lower()
    print ans

Submission status: Accepted

Solution code:
while(1):
    [inp, s]=raw_input().split()
    if s=='X':
        break
    else:
        words=[]
        if '_' in inp:
            words=inp.split('_')
        else:
            w=inp[0].lower()
            for c in inp[1:]:
                if c.isupper():
                    words.append(w)
                    w=c.lower()
                else:
                    w+=c
            words.append(w)
        if s=='D':
            print '_'.join(words)
        else:
            if s=='U':
                words=[w[0].upper()+w[1:] for w in words]
            else:
                words=[words[0]]+[w[0].upper()+w[1:] for w in words[1:]]
            print ''.join(words)

Submission status: Accepted

Solution code:
while True:
    words, type_ = input().split()
    if type_ == "L":
        if "_" in words:
            words = words.split("_")
            words = words[0] + "".join([w[0].upper() + w[1:] for w in words[1:]])
        else:
            words = words[0].lower() + words[1:]
    elif type_ == "U":
        if "_" in words:
            words = words.split("_")
            words = "".join([w[0].upper() + w[1:] for w in words])
        else:
            words = words[0].upper() + words[1:]
    elif type_ == "D":
        indices = [i for i, w in enumerate(words) if w.isupper()] + [len(words)]
        if words[0].islower():
            indices.insert(0, 0)
        words = "_".join([words[indices[i]].lower() + words[indices[i]+1: indices[i+1]] for i in range(len(indices) - 1)])
    else:
        break
    print(words)

Submission status: Accepted

Solution code:
while True:
    s, cc = input().split()
    if cc == "X":break
    if "_" in s:
        t = s.split("_")
    else:
        t = []
        j = 0
        for i in range(1, len(s)):
            if s[i].isupper():
                t.append(s[j:i])
                j = i
        t.append(s[j:])
    if cc == "U":
        for i in range(len(t)):t[i] = t[i][0].upper() + t[i][1:]
        print("".join(t))
    elif cc == "L":
        t[0] = t[0].lower()
        for i in range(1, len(t)):t[i] = t[i][0].upper() + t[i][1:]
        print("".join(t))
    else:
        for i in range(len(t)):t[i] = t[i].lower()
        print("_".join(t))

Submission status: Accepted

Solution code:
import re
while True:
    name,typ=raw_input().split()
    if name=="EndOfInput" and typ=="X":break
    if "_" in name:
        L=name.split("_")
    else:
        L=re.findall("[A-Z][a-z]*",name[0].upper()+name[1:])

    if typ=="D":
        print "_".join(map(lambda s:s.lower(),L))
    elif typ=="U":
        print "".join(map(lambda s:s.capitalize(),L))
    else:
        print L[0].lower()+"".join(map(lambda s:s.capitalize(),L[1:]))

Submission status: Accepted

Solution code:
upp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
low = "abcdefghijklmnopqrstuvwxyz"

while 1:
	a,type = raw_input().split()
	if type == "X": break
	ans = ""
	if type == "U":
		if "_" in a:
			words = a.split("_")
			for word in words:
				ans += upp[low.index(word[0])] + word[1:]
		else:
			ans = upp[low.index(a[0])] + a[1:] if a[0] in low else a
	elif type == "L":
		if "_" in a:
			words = a.split("_")
			ans += words[0]
			for word in words[1:]:
				ans += upp[low.index(word[0])] + word[1:]
		else:
			ans = low[upp.index(a[0])] + a[1:] if a[0] in upp else a
	else:
		if "_" not in a:
			words = []
			sp = 0
			for i in range(1,len(a)):
				if a[i] in upp:
					words.append(a[sp:i].lower())
					sp = i
			words.append(a[sp:].lower())
			ans = "_".join(words)
		else:
			ans = a
	print ans

Submission status: Accepted

Solution code:
while 1:
	a,type = raw_input().split()
	if type == "X": break
	ans = ""
	if type == "U":
		for word in a.split("_"):
			ans += word[0].upper() + word[1:]
	elif type == "L":
		for word in a.split("_"):
			ans += word[0].upper() + word[1:]
		ans = ans[0].lower() + ans[1:]
	else:
		if "_" not in a:
			words = []
			sp = 0
			for i in range(1,len(a)):
				if a[i].isupper() :
					words.append(a[sp:i].lower())
					sp = i
			words.append(a[sp:].lower())
			ans = "_".join(words)
		else:
			ans = a
	print ans

Submission status: Accepted

Solution code:
while True:
    a, b = map(str,input().split())
    if b=='X':
        break
    if '_' in a:
        c = a.split('_')
    else:
        c=[]
        k = 0
        for i in range(1,len(a)):
            if a[i].isupper():
                c.append(a[k:i])
                k = i
        c.append(a[k:])
    if b=='D':
        c = '_'.join(map(str.lower,c))
    else:
        c = ''.join(map(str.capitalize,c))
        if b =='L':
            c = c[0].lower() + c[1:]
    print(c)

Submission status: Accepted

Solution code:
while True:
    a, b = input().split()
    if b == 'X':
        break

    if '_' in a:
        ans = a.split('_')
    else:
        ans = []
        j = 0
        for i in range(1, len(a)):
            if a[i].isupper():
                ans.append(a[j:i])
                j = i
        ans.append(a[j:])
        
    if b == 'D':
        ans = '_'.join(map(str.lower, ans))
    else:
        ans = ''.join(map(str.capitalize, ans))
        
        if b == 'L':
            ans = ans[0].lower() + ans[1:]

    print(ans)

Submission status: Accepted

Solution code:
while True:
    a, b = input().split()
    if b == 'X':
        break

    if '_' in a:
        ans = a.split('_')
    else:
        ans = []
        j = 0
        for i in range(1, len(a)):
            if a[i].isupper():
                ans.append(a[j:i])
                j = i
        ans.append(a[j:])
        
    if b == 'D':
        ans = '_'.join(map(str.lower, ans))
    else:
        ans = ''.join(map(str.capitalize, ans))
        
        if b == 'L':
            ans = ans[0].lower() + ans[1:]

    print(ans)

Submission status: Accepted

Solution code:
import re
while True:
    n,t=map(str,input().split())
    if t == 'X':
        break
    if '_' in n :
        if t == 'D':
            print(n)
        else:
            m = n.title()
            l= re.sub('_', '',m)
            
            if t == 'U':
                print(l)
            elif t == 'L':
                p = l[0].lower() + l[1:]
                print(p)
    else:
        q = n[0].upper() + n[1:]
        r = re.findall('[A-Z][a-z]*',q)
        
        if t == 'D':
            s = '_'.join(r)
            print(s.lower())
        elif t == 'U':
            print("".join(r))
        elif t == 'L':
            u = "".join(r)
            v = u[0].lower() + u[1:]
            print(v)

Submission status: Accepted

Solution code:
while True:
    s=list(map(str,input().split(' ')))
    if s[1]=='X':
        break
    name=list(s[0])
    der=0
    n=[]
    for i in range(1,len(name)):
        if name[i].isupper()==True:
            n.append(i)
        if name[i]=='_':
            n.append(i-der)
            der+=1
    if s[1]=='U':
        name[0]=name[0].upper()
        for u in range(len(n)):
            if name[n[u]]=='_':
                name.pop(n[u])
                name[n[u]]=name[n[u]].upper()
        print(''.join(name))
    if s[1]=='L':
        name[0]=name[0].lower()
        for l in range(len(n)):
            if name[n[l]]=='_':
                name.pop(n[l])
                name[n[l]]=name[n[l]].upper()
        print(''.join(name))
    if s[1]=='D':
        if '_' in name:
            print(''.join(name))
        else:
            name[0]=name[0].lower()
            der=0
            for d in range(len(n)):
                name[n[d]+der]=name[n[d]+der].lower()
                name.insert(n[d]+der,'_')
                der+=1
            print(''.join(name))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import re
while True:
    name,type = input().split()
    if type == "X":
        break
    if "_" in name:
        X = name.split("_")
    else:
        tmp = name.upper()
        name = tmp[0]+name[1:]
        X = re.findall('[A-Z][^A-Z]*',name)
    if type == "U":
        for i in range(len(X)):
            X[i] = X[i].capitalize()
    elif type == "L":
        X[0] = X[0].lower()
        for i in range(1,len(X)):
            X[i] = X[i].capitalize()
    else:
        X[0] = X[0].lower()
        for i in range(1,len(X)):
            X[i] = "_"+X[i].lower()
    print("".join(X))

Submission status: Accepted

Solution code:
# coding: utf-8
# 89
import re

while True:
    n,t = input().split()
    if t == 'X':
        break
    if '_' in n:
        N=n.split('_')
        #print(N)
    else:
        i = n[0].upper()
        #print(i)
        k = n[1:]
        K = i +k
        #print(K)
        #N = re.split('[A-Z]',n)
        N = re.findall('[A-Z][^A-Z]*',K)
        #print(N)
    if t=='U':
        for i in range(len(N)):
            if i == len(N)-1:
                print(N[i].capitalize())
            else:
                print(N[i].capitalize(),end='')
    elif t=='L':
        for j in range(len(N)):
            if j == 0:
                if j==len(N)-1:
                    print(N[j].lower())
                else:
                    print(N[j].lower(),end='')
            elif j == len(N)-1:
                print(N[j].capitalize())
            else:
                print(N[j].capitalize(),end='')
        
    elif t=='D':
        for z in range(len(N)):
            if z == len(N)-1:
                print(N[z].lower())
            else:
                print(N[z].lower(),end='')
                print('_',end='')

Submission status: Accepted

Solution code:
while True:
    words, type_ = input().split()
    if type_ == "L":
        if "_" in words:
            words = words.split("_")
            words = words[0] + "".join([w[0].upper() + w[1:] for w in words[1:]])
        else:
            words = words[0].lower() + words[1:]
    elif type_ == "U":
        if "_" in words:
            words = words.split("_")
            words = "".join([w[0].upper() + w[1:] for w in words])
        else:
            words = words[0].upper() + words[1:]
    elif type_ == "D":
        indices = [i for i, w in enumerate(words) if w.isupper()] + [len(words)]
        if words[0].islower():
            indices.insert(0, 0)
        words = "_".join([words[indices[i]].lower() + words[indices[i]+1: indices[i+1]] for i in range(len(indices) - 1)])
    else:
        break
    print(words)

Submission status: Accepted

Solution code:
while True:
    a,b=input().split()
    if b=='X':
        break
    a=list(a)
    if ('_' in a) and (b=='U' or b=='L'):
        c=0
        for i in range(len(a)):
            if i==0 and b=='U':
                a[i]=a[i].upper()
            elif a[i]=='_':
                c+=1
            elif c==1:
                a[i]=a[i].upper()
                c=0
        a=[i for i in a if i!='_']
    elif b=='U':
        a[0]=a[0].upper()
    elif b=='L':
        a[0]=a[0].lower()
    else:
        s=0
        for i in range(len(a)):
            if i==0:
                a[0]=a[0].lower()
                s+=1
            elif a[s].isupper():
                a[s]=a[s].lower()
                a.insert(s,'_')
                s+=2
            else:
                s+=1
    for i in range(len(a)):
        if i==len(a)-1:
            print(a[i])
        else:
            print(a[i],end='')

Submission status: Accepted

Solution code:

while True:
    name,typ = input().split()
    if typ=="X": break
    ans = []
    
    if "_" in name:
        ans = name.split("_")
    else:
        j = 0
        for i in range(1,len(name)):
            if name[i].isupper():
                ans.append(name[j:i])
                j = i
        ans.append(name[j:])
                
    if typ=="D":
        ans = map(str.lower, ans)
        print(*ans,sep="_")
        
    else:
        ans = "".join(map(str.capitalize, ans))
        if typ=="L":
            ans = ans[0].lower() + ans[1:]
        print(ans)

Submission status: Accepted

Solution code:
import re
while True:
    n,t=input().split()
    
    if t=='X':
        break
    
    if '_'in t:
        ans=s.split('_')
    else :
        ans=re.findall(r'[a-z]+|[A-Z][a-z]*',n)
        
    if t=='D':
        ans='_'.join(map(str.lower,ans))
    else :
        ans=''.join(map(str.capitalize,ans))
        if t=='L':
            ans=ans[0].lower()+ans[1:]
    
    print(ans)

Submission status: Accepted

Solution code:
while True:
    s = input()
    s, order = s.split()
    if order == 'X':
        break
    if '_' in s:
        if order == 'U':
            s = s.split('_')
            a = ''
            for i in s:
                a += i.capitalize()
            print(a)
        elif order == 'L':
            s = s.split('_')
            a = ''
            a += s[0].lower()
            for i in s[1:]:
                a += i.capitalize()
            print(a)
        else:
            print(s.lower())
    else:
        if order == 'U':
            if s[0].isupper():
                print(s)
            else:
                s = s[0].upper() + s[1:]
                print(s)
        elif order == 'L':
            if s[0].islower():
                print(s)
            else:
                s = s[0].lower() + s[1:]
                print(s)
        else: 
            index = []
            c = 0
            for i in range(len(s[1:])):
                if s[i+1].isupper():
                    index.append(i + 1+c)
                    c += 1
            for j in index:
                s = s[: j] + '_' + s[j:]
            print(s.lower())

Submission status: Accepted

Solution code:
def Upper(s) :
    New = []
    i = 0
    while True :
        if i == 0 :
            New.append(s[i].upper())
        elif s[i] == "_" :
            i += 1
            New.append(s[i].upper())
        elif 65 <= ord(s[i]) <= 90 :
            New.append(s[i].upper())
        else :
            New.append(s[i].lower())
        i += 1
        if i >= len(s) :
            break
    return New

def Lower(s) :
    New = []
    i = 0
    while True :
        if s[i] == "_" :
            i += 1
            New.append(s[i].upper())
        elif 65 <= ord(s[i]) <= 90 and i != 0:
            New.append(s[i].upper())
        else :
            New.append(s[i].lower())
        i += 1
        if i >= len(s) :
            break
    return New

def Under_Score(s) :
    New = []
    i = 0
    while True :
        if 65 <= ord(s[i]) <= 90 and i != 0:
            New.append("_")
            New.append(s[i].lower())
        else :
            New.append(s[i].lower())
        i += 1
        if i >= len(s) :
            break
    return New

while True :
    l, x = map(str, input().split())
    if x == "X" :
        break
    
    elif x == "U" :
        print(*Upper(l), sep="")
    elif x == "L" :
        print(*Lower(l), sep="")
    elif x == "D" :
        print(*Under_Score(l), sep="")

Submission status: Accepted

Solution code:
while True:
    a, b = input().split()
    if b == 'X':
        break

    if '_' in a:
        ans = a.split('_')
    else:
        ans = []
        j = 0
        for i in range(1, len(a)):
            if a[i].isupper():
                ans.append(a[j:i])
                j = i
        ans.append(a[j:])
        
    if b == 'D':
        ans = '_'.join(map(str.lower, ans))
    else:
        ans = ''.join(map(str.capitalize, ans))
        
        if b == 'L':
            ans = ans[0].lower() + ans[1:]

    print(ans)

Submission status: Accepted

Solution code:
while True:
    Name, Type = input().split()
    
    if Type=='X':
        break
    
    if '_' in Name:
        
        Name_ = Name
        _n_ = [0]
        i = 0
        while True:
            Namelist_ = list(Name_)
            n_ = Name_.find('_')
            if n_==-1:
                break
            _n_.append(n_+_n_[i])
            i += 1
            del(Namelist_[0:n_+1])
            Name_ = ''.join(Namelist_)
        
        Name = ''.join(Name.split('_'))
        Namelist = list(Name)
        for i in range(len(_n_)):
            o = str(Namelist[_n_[i]])
            O = o.upper()
            Namelist.pop(_n_[i])
            Namelist.insert(_n_[i],O)
        Name = ''.join(Namelist)
        
    if Type=='U':
        NameLIST = list(Name)
        o = str(NameLIST[0])
        O = o.upper()
        NameLIST.pop(0)
        NameLIST.insert(0,O)
        NAME = ''.join(NameLIST)
    
    if Type=='L':
        NameLIST = list(Name)
        O = str(NameLIST[0])
        o = O.lower()
        NameLIST.pop(0)
        NameLIST.insert(0,o)
        NAME = ''.join(NameLIST)
    
    if Type=='D':
        NameLIST = list(Name)
        _T_ = []
        t = 0
        for i in range(len(NameLIST)):
            T = str(NameLIST[i])
            if T.isupper()==False:
                pass
            if T.isupper()==True:
                if i==0:
                    pass
                if i>0:
                    _T_.append(i+t)
                    t += 1
                Tt = T.lower()
                NameLIST.pop(i)
                NameLIST.insert(i,Tt)
        for i in range(len(_T_)):
            NameLIST.insert(_T_[i],'_')
        NAME = ''.join(NameLIST)
        
    
    print(NAME)

Submission status: Accepted

Solution code:
while True :
    name, type = map(str, input().split())
    
    if type == "X" :
        break
    
    else :
        N = list(name)
        
        if "_" in N :
            if type == "U" or type == "L" :
                cnt = 0
                
                for i in range(len(N)) :
                    if i == 0 and type == "U" :
                        N[i] = N[i].upper()
                    elif N[i] == "_" :
                        cnt += 1
                    elif cnt == 1 :
                        N[i] = N[i].upper()
                        cnt = 0
                
                N = [i for i in N if i != "_"]
                
        elif type == "U" :
            N[0] = N[0].upper()
            
        elif type == "L" :
            N[0] = N[0].lower()
            
        else :
            s = 0
            for i in range(len(N)) :
                if i == 0 :
                    N[s] = N[s].lower()
                    s += 1
                elif N[s].isupper() :
                    N[s] = N[s].lower()
                    N.insert(s, "_")
                    s += 2
                else :
                    s += 1
            
        for i in range(len(N)) :
            if i == len(N) - 1 :
                print(N[i])
            else :
                print(N[i], end = "")

Submission status: Accepted

Solution code:
while True:
    s,cc=input().split()
    if cc=="X":
        break
    if "_" in s:
        t = s.split("_")
    else:
        t = []
        j = 0
        for i in range(1, len(s)):
            if s[i].isupper():
                t.append(s[j:i])
                j = i
        t.append(s[j:])
    if cc == "U":
        for i in range(len(t)):
            t[i] = t[i][0].upper() + t[i][1:]
        print("".join(t))
    elif cc == "L":
        t[0] = t[0].lower()
        for i in range(1, len(t)):
            t[i] = t[i][0].upper() + t[i][1:]
        print("".join(t))
    else:
        for i in range(len(t)):
            t[i] = t[i].lower()
        print("_".join(t))

Submission status: Accepted

Solution code:
from string import ascii_uppercase
while 1:
    s, t = input().split()
    if t == 'X':
        break
    if "_" in s:
        W = s.split("_")
    else:
        W = []; w = []
        for c in s:
            if c in ascii_uppercase:
                if w:
                    W.append("".join(w).lower())
                w = [c]
            else:
                w.append(c)
        if w:
            W.append("".join(w).lower())
    if t == 'D':
        print(*W, sep='_')
    elif t == 'U':
        print(*map(lambda x: x.capitalize(), W), sep='')
    else:
        print(W[0], *map(lambda x: x.capitalize(), W[1:]), sep='')

Submission status: Accepted

Solution code:
import re

while True:
    s, c = input().split()
    if c == 'X':
        break

    if '_' in s:
        t = s.split('_')
    else:
        t = re.findall(r'^[a-z]+|[A-Z][a-z]*', s)

    if c == 'D':
        t = '_'.join(map(str.lower, t))
    else:
        t = ''.join(map(str.capitalize, t))
        if c == 'L':
            t = t[0].lower() + t[1:]

    print(t)

Submission status: Accepted

Solution code:
large = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
small = list("abcdefghijklmnopqrstuvwxyz")

while 1:
    word, alpha = input().split()
    if alpha == "X":
        break

    word = list(word)

    ans = ""
    if alpha == "L":
        first = word.pop(0)
        if first in large:
            ans += small[large.index(first)]
        else:
            ans += first

        while word != []:
            w = word.pop(0)
            if w == "_":
                target = word.pop(0)
                if target in small:
                    ans += large[small.index(target)]
                else:
                    ans += target
            else:
                ans += w

    elif alpha == "U":
        first = word.pop(0)
        if first in small:
            ans += large[small.index(first)]
        else:
            ans += first

        while word != []:
            w = word.pop(0)
            if w == "_":
                target = word.pop(0)
                if target in small:
                    ans += large[small.index(target)]
                else:
                    ans += target
            else:
                ans += w

    elif alpha == "D":
        first = word.pop(0)
        if first in large:
            ans += small[large.index(first)]
        else:
            ans += first

        while word != []:
            w = word.pop(0)
            if w in large:
                ans += "_" + small[large.index(w)]
            else:
                ans += w

    print(ans)

Submission status: Accepted

Solution code:
while True:
  n, t = input().split()
  if t == "X":
    break

  if "_" in n:
    names = n.split("_")
  else:
    n = list(n)
    for i, c in enumerate(n):
      if c.isupper():
        if i:
          n[i] = "#" + c.lower()
        else:
          n[i] = c.lower()
    names = "".join(n).split("#")

  if t == "U":
    print(*[name.title() for name in names], sep="")
  elif t == "L":
    print(*[name.title() if i !=  0 else name for i, name in enumerate(names)], sep="")
  else:
    print(*names, sep="_")