Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CCC '15 S1 - Zero That Out Canadian Computing Competition: 2015 Stage 1, Senior #1 Your boss has asked you to add up a sequence

image text in transcribed
image text in transcribed
CCC '15 S1 - Zero That Out Canadian Computing Competition: 2015 Stage 1, Senior #1 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 can 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) "One, three, five, four" "zero, zero seven" "zero, zero -six" Current numbers 1, 3, 5, 4 1, 3 1, 3, 7 Explanation Record the first four numbers. ignore the last two numbers Record the number 7 at the end of our list gnore the last two numbers We have read all numbers, and the total is 7 At any point, your boss wil 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. Input Specification The first line of input contains the integer K (1KK100000) which is the number of integers (including "zero") your boss will say On each of the K lines, there will either be one integer between 1 and 100 (inclusive) or the integer 0 Output Specification 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 1000000 (inclusive). Sample Input 1 12

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is the environment we are trying to create?

Answered: 1 week ago

Question

How would we like to see ourselves?

Answered: 1 week ago