B. Sum and maximum

    传统题 1000~2500ms 256MiB

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 ii-th of which is an integer sis_i. The last line is 0.

  • For 100% cases, si100|s_i|\leq 100.
  • 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.

CS100 Spring2025 Homework 1

未认领
状态
已结束
题目
5
开始时间
2025-2-28 0:00
截止时间
2025-3-9 23:59
可延期
0 小时