RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
문제 R03699

S1. Zero That Out

설명

Your boss has asked you to add up a sequence of positive numbers to
determine how much money your company made last year.

Unfortunately, your boss reads out numbers incorrectly from time to
time.

Fortunately, your boss realizes when an incorrect number is read and
says “zero”, meaning “ignore the current last number.”

Unfortunately, your boss can make repeated mistakes, and says “zero”
for each mistake.

For example, your boss may say “One, three, five, four, zero, zero,
seven, zero, zero, six”, which means the total is 7 as explained in the
following chart:

Boss statement(s) Current numbers Explanation
“One, three, five, four” 1, 3, 5, 4 Record the first four numbers.
“zero, zero” 1, 3 Ignore the last two numbers.
“seven” 1, 3, 7 Record the number 7 at the end of our list.
“zero, zero” 1 Ignore the last two numbers.
“six” 1, 6 We have read all numbers, and the total is 7.

At any point, your boss will have said at least as many positive
numbers as “zero” statements. If all positive numbers have been ignored,
the sum is zero.

Write a program that reads the sequence of boss statements and
computes the correct sum.

제약
입력 형식

The first line of input contains the integer \(K(1 \leq K \leq 100 \ 000)\) which is the number of integers (including
“zero”) your boss will say. On each of the next \(K\) lines, there will either be one integer
between \(1\) and \(100\) (inclusive), or the integer \(0\).

출력 형식

The output is one line, containing the integer which is the correct
sum of the integers read, taking the “zero” statements into
consideration. You can assume that the output will be an integer in the
range \(0\) and \(1\ 000\ 000\) (inclusive).

예제 1
입력
4
3
0
4
0
출력
0
예제 2
입력
10
1
3
5
4
0
0
7
0
0
6
출력
7
문제 정보

생성자가 기록되지 않았습니다.

출처 CCC 2015 Senior

평가 및 의견

S1. Zero That Out

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

S1. Zero That Out

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8