Sum and maximum
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
Problem 2. Sum and maximum
Description
Class Exercise 1
Write a program that reads an unknown number of integers from input until 0 is entered. Print the sum and the maximum of these integers.
Input format
Several lines, the -th of which is an integer . The last line is 0
.
- For 100% cases, .
- All the integers before the last line are nonzero.
Output format
Two lines:
sum: xxx
maximum: yyy
where xxx
and yyy
are replaced with the sum and the maximum of the input integers. Note that the terminating 0
is not counted.
Examples
Example 1
Input:
1
2
3
0
Output:
sum: 6
maximum: 3
Example 2
Input:
-1
-2
-3
0
Output:
sum: -6
maximum: -1
Notes
This problem should be solved without arrays or dynamic memory allocation. Keep your solution simple.