Tournament P26606


Statement
 

pdf   zip

Consider an all-play-all tournament, in which each team (or player) will meet every other participant exactly once, in turns. For instance, if we have n=2mn = 2m football teams, we will have mm concurrent matches in n1n - 1 different days. In the end, we aim for each team to have competed against all the other teams. Additionally, for fairness, we want every team to play mm times at home and m1m-1 times away, or m1m-1 times at home and mm times away. A similar situation would arise in a chess tournament, where we require all the players to have as many white pieces as black pieces (plus minus one).

Given the nn names of the teams (or players), can you schedule all the matches?

Input

Input consists of several cases, each with nn, followed by nn different names made up of only lowercase letters. Assume 2n10002 \le n \le 1000, and that nn is even.

Output

Print nn lines for each case. The first n1n-1 lines should have mm matches separated by spaces. A match is a pair of names separated by a dash, where the first team plays at home and the second team plays away. End each case with a line with 10 asterisks. Since there is more than one solution, print any one. Follow strictly the format of the sample output.

Public test cases
  • Input

    2 barca sampdoria
    4 karpov kasparov fischer spassky
    6 a b c d e f
    

    Output

    sampdoria-barca
    **********
    spassky-karpov kasparov-fischer
    karpov-fischer spassky-kasparov
    kasparov-karpov fischer-spassky
    **********
    e-c f-b d-a
    b-a c-f d-e
    c-d f-a b-e
    f-d b-c a-e
    e-f a-c d-b
    **********
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++