본문 바로가기

Programming/Etc

Hackerrank / ginorts

링크 :  https://www.hackerrank.com/contests/pythonist3/challenges/ginorts/problem

 

소문자, 대문자, 홀수, 짝수 순으로 재배치되어 나오는 문제이다.

 

Sample Input

Sorting1234

Sample Output

ginortS1324

 

 

def solve(s):
    char = list(s)
    alpha = 'abcdefghijklmnopqrstuvwxyz'
    alpha_b = list(alpha.upper())
    alpha_s = list(alpha)

    big = []
    small = []
    num_0 = []
    num_1 = []
    
    for c in char:
        if c in ['0','2','4','6','8']:
            num_0.append(ord(c))
        elif c in ['1','3','5','7','9']:
            num_1.append(ord(c))
        elif c in alpha_b:
            big.append(ord(c))
        elif c in alpha_s:
            small.append(ord(c))
            
    result = ''
    answer = sorted(small)+sorted(big)+sorted(num_1)+sorted(num_0)
    
    for s in answer:
        result+=chr(s)

    return result

if __name__ == '__main__':
    s = input()
    print(solve(s))

'Programming > Etc' 카테고리의 다른 글

소수 찾기 효율성  (0) 2022.02.15
Programmers / 문자열 압축  (0) 2022.02.11
Hackerrank / Write a function  (0) 2022.01.18
Hackerrank / Iterables and Iterators  (0) 2021.12.03
programmers / 로또 최고 최저  (0) 2021.12.01