Positions of a maximum within two sequences X58169


Statement
 

pdf   zip

Given two sequences of non negative integers s1s_1 and s2s_2 both ending in 00, write a program that computes the maximum mm of the elements in s1s_1 and that shows the position of its latest occurrence within s1s_1 and the position of its first ocurrence within s2s_2.

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 s1s_1 and s2s_2 of non negative integers, both ending in 00. The sequence s1s_1 is not empty (i.e., it has at least one element different from the ending mark), but the sequence s2s_2 can be empty.

Output

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

 
Please, follow the specified format.

 

Public test cases
  • Input

    1 2 3 4 5 6 7 8 9 0
    9 8 7 6 5 4 3 2 1 0
    

    Output

    9 9 1
    
  • Input

    1 2 3 3 3 2 1 0
    3 2 1 0
    

    Output

    3 5 1
    
  • Input

    1 2 4 8 16 32 16 8 4 2 1 0
    1 3 9 27 0
    

    Output

    32 6 -
    
  • Input

    1 2 4 8 16 32 16 8 4 2 1 0
    0
    

    Output

    32 6 -
    
  • Information
    Author
    Maria J. Serna i Maria J. Blesa
    Language
    English
    Translator
    Maria J. Blesa
    Original language
    Catalan
    Other languages
    Catalan Spanish
    Official solutions
    Unknown.
    User solutions
    C++