티스토리 뷰

python lecture/project

[python] # 연산 하기

burningrizen 2020. 5. 11. 22:38

아래와 같은 연산을 하는 함수를 작성한다.

더보기

입력출력 결과

input

> 123, 11

output

> 132131

 

input

> 144345, 13

output

> 12433251

 

input

> 153, 12

output

> 12513121

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

def add(a, b):
    return str(a) + str(b)


def count(t, s):
    return f"{t}{s.count(t)}"


def remove(t, s):
    return s.replace(t, "")


def foo(a, b):
    r = ""
    s = add(a, b)
    while s:
        r += count(s[0], s)
        s = remove(s[0], s)
    return int(r)


print(foo(11, 14))

'python lecture > project' 카테고리의 다른 글

[python] 스테가노그래피  (0) 2020.05.25
[python] 남/여 균일 매칭  (0) 2020.05.25
[python] 원소기호 맞추기  (0) 2020.05.09
[python] 주문시스템  (0) 2020.05.09
[blockchain] 블록체인 예제  (0) 2020.05.07
댓글