Codeforces/Python
[Codeforces] 282A - BIt++ (Python)
tjdms4327
2025. 5. 13. 10:41
문제
operation '++'는 x를 1 증가시키고 '--'는 1 감소시킨다.
n줄에 입력된 operation들을 실행하여 최종 x값을 구하라.
풀이
operation의 위치는 실행과 상관없으므로 각 줄의 operation에 '++' 혹은 '--'이 포함되어 있는지만 보면 된다.
간단하게 하기 위해 string으로 입력받아 각각이 포함되어있는가를 보고 포함되어 있다면 1을 증/감소시킨다.
코드
n=int(input())
x=0
for _ in range(n):
operation=input()
if '++' in operation: x+=1
elif '--' in operation: x-=1
print(x)