Maximum and Minimum Until Zero

1.0s 256M

The input gives several positive integers, followed by a final \(0\) that marks the end.

Find the maximum and minimum among all positive integers before the \(0\). The final \(0\) is only a terminator and is not part of the numbers.

Syntax Restrictions

This problem uses the syntax restrictions of Unit 4 (Loops) of the syntax textbook. You may use if, else, loops, comparisons, logical operators, integer variables, cin, cout, and cout << endl; however, you may not use arrays or containers, and you may not use any function other than main (including built-in functions and user-defined functions). The name endl is allowed only as an output newline manipulator, not as a function call.

Your source code is checked automatically during judging. A submission that breaks the restrictions is judged SR (Syntax Restriction), and the judge feedback lists where the violation is.

Click to expand: allowed and forbidden syntax

Allowed:

  • #include <iostream> or other ordinary includes (no extra header is needed)
  • using namespace std;
  • the int main() function and return 0;
  • integer, Boolean, and character variables, such as int, long long, bool, and char
  • reading with cin >> and printing with cout <<, including cout << endl
  • if, else, for, and while
  • arithmetic, comparison, and logical operators, such as +, -, *, /, %, <, <=, ==, and &&
  • assignment and increment/decrement, such as =, +=, ++, and --
  • comments (// and /* */)

Forbidden (common examples):

  • arrays and indexing syntax []
  • containers or similar tools such as vector, array, string, deque, map, and set
  • dynamic allocation syntax such as new and delete
  • any function call or function declaration other than main, including max, min, abs, sqrt, pow, sort, swap, getline, printf, and scanf
  • non-include preprocessor directives such as #define

Input

The input contains several lines. Each line contains one integer.

There is at least one positive integer first. The last line is always \(0\), meaning the input ends.

Constraints

  • There are at least \(1\) and at most \(1000\) positive integers before the \(0\).
  • Each positive integer is between \(1\) and \(10000\).
  • The final \(0\) is not included when finding the maximum and minimum.
  • The memory limit is \(256\) MB.

Output

Output one line with two integers: the maximum value and the minimum value, separated by one space.

Sample Input 1

5
2
9
1
0

Sample Output 1

9 1

Sample Input 2

7
0

Sample Output 2

7 7

Problem page help

Keyboard shortcuts

Main features

  • Sample tests — Runs the sample cases bundled with the problem and auto-compares against the expected output.
  • Custom test — Run your code with your own stdin. Optionally tick the "Compare with expected (diff)" box to verify against expected output line-by-line.
  • Template — Paste the default code template you set on your profile page.
  • Collab — Edit this problem together with classmates in real time.
  • Auto-draft — Editor contents auto-save to your browser every 1.5 seconds (per account / problem / language).
  • Submit — Send your code to the judge for grading; returns AC / WA / TLE etc.

Limits

  • Source code: at most 65,536 characters
  • Custom test stdin and expected output: at most 1 MB each (≈1 million characters)
  • Custom test: about 1 request per 3 s per user (sample test: 1 per 1 s)
  • Custom test has a 15 second wall-clock cap; sample tests use the problem time limit, the same as the official judge
  • Interactive problems do not offer custom test (cannot simulate interaction with the judge).
  • Submitting has no rate limit, but rapid repeated submissions on the same problem are treated as score farming.