Positions of a maximun in two sequences

Given two sequences of non negative integers s₁ and s₂ both ending in 0,
write a program that computes the maximum m of the elements in s₁ and
that shows the position of its latest occurrence within s₁ and the
position of its first ocurrence within s₂.

In your program, you must implement and use the following procedure:

  void infoSequence(int& max, int& lpos);

which reads a sequence ending in 0 and computes the parameters max and
lpos. At the end of the execution of the procedure, the parameter max
must hold the largest value in the sequence and the parameter lpos has
to hold the position of the latest occurrence of the maximum value.

Input

The input is formed by two sequences s₁ and s₂ of non negative integers,
both ending in 0. The sequence s₁ is not empty (i.e., it has at least
one element different from the ending mark), but the sequence s₂ can be
empty.

Output

The output is formed by three items: The maximum element in s₁, m, the
position of the latest occurrence of m in s₁, and the position of the
first occurrence of m in s₂. The case in which m does not form part of
s₂, or when s₂ is an empty sequence (and, therefore m does not form part
of s₂) must be conveniently indicated.

 
Please, follow the specified format.

 

Problem information

Author: Unknown
Translator: Maria J. Blesa

Generation: 2026-01-25T21:50:31.861Z

© Jutge.org, 2006–2026.
https://jutge.org
