haju__log

[python][SWEA][D3] 14555. 공과 잡초 본문

SWEA

[python][SWEA][D3] 14555. 공과 잡초

haju 2023. 5. 14. 13:29

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=2&problemLevel=3&contestProbId=AYGtoa3qARcDFARC&categoryId=AYGtoa3qARcDFARC&categoryType=CODE&problemTitle=&orderBy=PASS_RATE&selectCodeLang=PYTHON&select-1=3&pageSize=10&pageIndex=6 

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

✅ 문제 풀이

  • 조건 이해가 관건인 문제..!
  • 초원에 놓였을 수 있는 공이란 잡초로 쪼개져있더라도 공으로 만들어 질 수 있는 상태를 세야함
  • (| , |) , () 세 가지인 경우의 수를 세야한다는 뜻이다.
T=int(input())

for test_case in range(1,T+1):
    s=input()
    result=0
    for i in range(len(s)-1):
        if s[i]=='(' and s[i+1]=='|' or s[i]=='|' and s[i+1]==')' or s[i]=='(' and s[i+1]==')':
            result+=1
    print("#%d %d" %(test_case,result))