Intervals (1) P51126


Statement
 

pdf   zip

Write a program that, given two intervals, computes the interval corresponding to their intersection, or tells that it is empty.

Input

Input consists of four integer numbers a1a_1, b1b_1, a2a_2, b2b_2 that represent the intervals [a1,b1][a_1,b_1] and [a2,b2][a_2,b_2]. Assume a1b1a_1\le b_1 and a2b2a_2\le b_2.

Output

Print “[]” if their intersection is empty, or “[xx,yy]” if this is their non-empty intersection.

Public test cases
  • Input

    20 30   10 40
    

    Output

    [20,30]
    
  • Input

    10 20   10 20
    

    Output

    [10,20]
    
  • Input

    20 30   10 20
    

    Output

    [20,20]
    
  • Input

    10 20   30 40
    

    Output

    []
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++ Java Python
    User solutions
    C C++ Java JavaScript Lua PHP Python Rust Zig