Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

짱이 될거야

백준 25501: 재귀의 귀재 Python 본문

알고리즘

백준 25501: 재귀의 귀재 Python

jeong57 2022. 11. 25. 09:47

https://www.acmicpc.net/problem/25501

 

25501번: 재귀의 귀재

각 테스트케이스마다, isPalindrome 함수의 반환값과 recursion 함수의 호출 횟수를 한 줄에 공백으로 구분하여 출력한다.

www.acmicpc.net

 

 

def isPalindrome(s):
    return recursion(s, 0, len(s)-1)


def recursion(s, l, r):     # s: 문자열, l: 시작, r: 끝
    global count
    count += 1
    if l >= r:
        return 1
    elif s[l] != s[r]:
        return 0
    else:
        return recursion(s, l+1, r-1)


T = int(input())    # 테스트케이스의 수
for _ in range(T):
    count = 0       # recursion 함수의 호출 횟수
    print(isPalindrome(input()), end=' ')
    print(count)

'알고리즘' 카테고리의 다른 글

백준 7569: 토마토 Python (BFS)  (0) 2022.11.28
백준 3009: 네 번째 점 Python  (0) 2022.11.25
백준 2566: 최댓값 Python  (0) 2022.11.24
백준 2738: 행렬 덧셈  (0) 2022.11.24
백준 10807: 개수 세기 Python  (0) 2022.11.23
Comments