Identifying Sections X39296


Statement
 

pdf   zip

html

Given a sequence of integers, we specify a “section” of it using two integers a and b. The section is the part of the sequence that starts immediately after the first occurrence of a, if any, and ends immediately before the first occurrence of b after the first occurrence of a, if any.

For instance, given the sequence 6, 5, 1, 2, 1, 4, 3, 5, 4, 3, 5, 1 with a = 1 and b = 5 we specify the subsequence 2, 1, 4, 3 that starts just after the first 1 and ends just before the first 5 after that 1.

Write a program that reads in a number of cases, each case specifying a section, and prints out the sections specified. The input indicates, for each case, first a and b, followed by the length of the sequence n, all three in one line, separated with whitespace; the subsequent line (or lines) bring n integers constituting the sequence, and after them, in a separate line, may start a new case.

For each case, the sequence identified can be empty; there are three such cases: (1) when a does not appear in the sequence, (2) when it appears but b does not appear subsequently, and (3) when both appear but there are no intervening numbers. In these cases, your program must print appropriately nothing.

The sections indentified must be printed on one line each. After each case, print a line with ten dashes: ----------.

Public test cases
  • Input

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

    Output

    2 1 4 3 
    ----------
    
    ----------
    
    ----------
    
    ----------
    8 1 2 1 4 3 5 4 3 5 
    ----------
    
  • Information
    Author
    José Luis Balcázar
    Language
    English
    Official solutions
    Python
    User solutions
    Python