본문 바로가기

파이썬 알고리즘 (인프런)/코드 구현력 기르기

10. 점수계산

# 점수계산

def run(N, a):
    scores = [0] * N
    if a[0] == 1:
        scores[0] = 1

    for i in range(1, N):
        if a[i] == 1:
            scores[i] = scores[i-1] + 1

    return sum(scores)


def run(N, a):
    score, tot = 0,  0
    for x in a:
        if x == 1:
            score += 1
            tot += score
        else:
            score = 0

    return tot  # 총점


N = int(input())
a = list(map(int, input().split()))

print(run(N, a))

'파이썬 알고리즘 (인프런) > 코드 구현력 기르기' 카테고리의 다른 글

9. 주사위 게임  (0) 2021.01.06
8. 뒤집은 소수  (0) 2021.01.06
7. 소수 (에라토스테네스 체)  (0) 2021.01.06
6. 자릿수의 합  (0) 2021.01.06
5. 정다면체  (0) 2021.01.06