Notice
Recent Posts
Recent Comments
Link
Star_project
[인프런] 2. 자료구조와 알고리즘 입문 10.점수 계산 본문
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 를 사실상 합칠 수 있음.
'코딩테스트 > Python' 카테고리의 다른 글
[인프런] 3.탐색&시뮬레이션(string, 1차원, 2차원 리스트 탐색 ) 2.숫자만추출 (0) | 2022.07.12 |
---|---|
[인프런] 3.탐색&시뮬레이션(string, 1차원, 2차원 리스트 탐색 ) 1.회문 문자열 검사 (0) | 2022.07.12 |
[인프런] 2. 자료구조와 알고리즘 입문 9.주사위 게임 (0) | 2022.07.12 |
[인프런] 2. 자료구조와 알고리즘 입문 8. 뒤집은 소수 (0) | 2022.07.12 |
[프로그래머스] 자릿수 더하기 (0) | 2022.07.11 |