Notice
Recent Posts
Recent Comments
Link
관리 메뉴

Star_project

[인프런] 2. 자료구조와 알고리즘 입문 10.점수 계산 본문

코딩테스트/Python

[인프런] 2. 자료구조와 알고리즘 입문 10.점수 계산

star빛 2022. 7. 12. 14:59
import sys
sys.stdin=open("pythonalgorithm/섹션 2/10. 점수 계산/in2.txt","rt")
n=int(input())
a=list(map(int,input().split()))
score=ch=0
for x in a:
    if x==1 and ch==0:
        score+=1
        ch+=1
    elif x==1 and ch>0:
        score+=(1+ch)
        ch+=1
    else:
        ch=0
print(score)

내가 푼 풀이

import sys
sys.stdin=open("pythonalgorithm/섹션 2/10. 점수 계산/in2.txt","rt")
n=int(input())
a=list(map(int,input().split()))
score=ch=0
for x in a:
    if x==1:
        score+=1+ch
        ch+=1
    else:
        ch=0
print(score)

if와 elif 를 사실상 합칠 수 있음.