practivceAlgorithm/백준

[백준][Python] 3613 Java vs C++

findTheValue 2021. 9. 2. 09:57

리팩터링은 귀찮아서 못하겠슴둥..

1. 맨앞 대문자

2. 대문자와 _ 가 같이 나오는 경우

 

import sys
input = sys.stdin.readline

var = input().rstrip()
if var[0]=='_':
    print('Error!')
    exit()
var_name = var.split('_')

if len(var_name) > 1:
    answer = ''
    for char in var_name[0]:
        if char.isupper():
            print('Error!')
            exit()
        answer += char
    for var in var_name[1:]:
        if var:
            if var[0].isupper():
                print('Error!')
                exit()
            answer += var[0].upper()
            for char in var[1:]:
                if char.isupper():
                    print('Error!')
                    exit()
                answer += char
        else:
            print('Error!')
            exit()
else:
    answer = ''
    if var[0].isupper():
        print('Error!')
        exit()
    answer += var[0]
    for char in var[1:]:
        if char.isupper():
            answer += '_' + char.lower()
        else:
            answer += char
print(answer)