Embercode
✕
Linked ListsCoding problems

Linked Lists: coding problems

Write a program that reads the input and prints the answer. Run checks it against every test, including hidden ones.

0 of 8 solved

  • A corner shop writes the price of each item on a card and links the cards in the order they were made. At the end of the day the owner wants the total of every price. Some prices are negative, because the shop records refunds on the same list. Walk the list once and print the total.

    The total can be bigger than an int can hold, so use a long for the sum.

    Constraints: 1 <= n <= 4000, and every value is between -40000000 and 40000000.

    Input. First line n. Second line n integers, the prices in list order.

    Output. One integer, the sum of all values.

    Example 1 input

    3
    4 5 6
    

    Output

    15
    

    Example 2 input

    4
    -2 10 -3 7
    

    Output

    12