pangfengliu / programmingtasks

programming tasks from my courses
68 stars 17 forks source link

Scan the Blocks #333

Open littlehug opened 6 years ago

littlehug commented 6 years ago

Task Description

You will be given a sequence of blocks. Each block starts with an N that indicates the number of integers in the block, then follows with a sequence of N integers. Write a program to read the sequence of blocks until the end of file, and print the maximum or the minimum in each block according to the following rules. Note that to make the maximum and minimum well-defined we assume that every block has at least one number. Also we assume that there is at least one block.

Let us illustrate the task with two examples. If we are given [3, -14, 36, 7], [2, 79, 24], [2, 15, 9], then we should print 36, 79, 15 since every block is complete and we need to print the maximum. If we are given [4, 34, 17, 0, 97], [1, 37], [2, 1, -12], [5, 13, -5, 63] then we need to print 97, 37, 1, -5 because the last block is incomplete, and we need to print the minimum. Note again that only the last block could be incomplete.

Subtask

Input Format

The input contains only one test case. Each test case contains a sequence of integers.

Output Format

Print all integers on separate lines.

Sample Input 1

3 -14 36 7 2 79 24 2 15 9

Sample Output 1

36
79
15

Sample Input 2

4 34 17 0 97 1 37 2 1 -12 5 13 -5 63

Sample Output 2

97
37
1
-5

Note

Do not use array for this problem. You can solve this problem with very little memory. We will make sure that you will not have enough memory, and see the "memory limit exceeded" error, if you use array.