Mock CCC '18 Contest 3 J1 - A Sum Problem

View as PDF

Submit solution


Points: 3 (partial)
Time limit: 1.0s
Memory limit: 1G

Problem type

Given a list of integers, compute the sum of the nonzero ones.

In the event the list contains no nonzero integers, the desired sum is zero.

Constraints

1 \le N \le 10

-5 \le a_i \le 5

In tests worth 5 marks, all a_i are nonzero.

Input Specification

The first line contains a single integer N.

The next N lines each contain a single integer, a_i, representing the ith integer in the list.

Output Specification

On a single line, output the sum of the nonzero integers.

Sample Input 1

10
0
0
0
0
0
0
0
0
0
0

Sample Output 1

0

Sample Input 2

2
1
-2

Sample Output 2

-1

Comments


  • 2
    mateobarbosa  commented on Oct. 21, 2023, 3:30 p.m.

    if you guys are getting a "Presentation error: check your whitespace" put a new line after you output the sum of the list


  • 1
    charliezhao06  commented on Dec. 3, 2019, 10:26 p.m.

    A few questions: Why do we get 1G and what's the point of emphasizing non-zero Integers, even if you were to add them, it would't make a difference.


    • 63
      wleung_bvg  commented on Dec. 3, 2019, 10:57 p.m.

      Red Herring


      • 5
        charliezhao06  commented on Dec. 3, 2019, 11:36 p.m.

        Ohhh I get it now, thanks for telling me