본문 바로가기
python-algorithm

백준 10205 헤라클레스와 히드라

by 무적김두칠 2022. 10. 22.
def sol(n,s):
    for i in s:
        if i=='c':
            n+=1
        elif i=='b':
            n-=1
        if n==0:
            return 0
    return n
k=int(input())
for i in range(k):
    print("Data Set %d:"%(i+1))
    n=int(input())
    s=input()
    print(sol(n,s))
    if i!=k-1:
        print()

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

 

10205번: 헤라클레스와 히드라

헤라클레스는 그리스 신화의 유명한 비극적인 영웅이다. 그는 제우스의 사생아로 태어났는데, 이때문에 제우스의 아내 헤라는 그를 매우 싫어했다. 그는 매우 강한 힘과 높은 지식을 가졌지만,

www.acmicpc.net

조건문과 간단한 문자열 처리입니다
Use If clause and string implement

반응형

'python-algorithm' 카테고리의 다른 글

백준 8949 대충 더해  (0) 2022.10.24
백준 2154 수 이어 쓰기 3  (0) 2022.10.23
백준 25640 MBTI  (0) 2022.10.21
백준 15000 CAPS  (0) 2022.10.21
백준 25372 성택이의 은밀한 비밀번호  (0) 2022.10.20

댓글