ECOO '12 R3 P1 - The Word Garden

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 2.0s
Memory limit: 64M

Problem type

In addition to creating problems for the ECOO competition, I have an unusual landscaping business on the side. I create custom-made "Word Gardens". To make a Word Garden, I take one of my customers' favourite quotations, turn each word in the quotation into a tree, and then plant the trees in rows, packing them as tightly together as I can.

Here's an example, using a paraphrased quote from Hubert Dreyfus' classic book, What Computers Can't Do. The original quote was, "Since the Greeks invented logic and geometry the idea that all reasoning might be reduced to some kind of calculation has fascinated most of the West's rigorous thinkers".

             G      invenevni
            GrG    inventnevni
    S      GrerG  inventetnevni  l
   SiS    GreeerGinventedetnevnilol
  SiniS  GreekeerG      i      logol
 SincniSGreekskeerG     n     logigol
SincecniSt   G          v    logicigol
    S   tht  r          e        l
    i  theht e          n        o
    n    t   e          t        g
    c    h   k          e        i
    e    e   s          d        c

       g                    reaer
      geg                  reasaer
     geoeg                reasosaer
    geomoeg              reasonosaer
   geomemoeg            reasoninosaer
  geometemoeg          reasonininosaer
 geometrtemoeg        reasoningninosaer
geometryrtemoeg               r
       g       i      t       e
       e      idi    tht      a
  a    o  t  idedi  thaht  a  s
 ana   m thtideaedithatahtala o
andna  etheht  i      t  alllan
  a    t  t    d      h    a  i
  n    r  h    e      a    l  n
  d    y  e    a      t    l  g

    m    reducuder
   mim  reducecuder
  migimreducedecuders      k
 mighgim     r     sos    kik
mighthgim    e    somos  kinik
    m        d   somemoskindnik
    i b      u t    s      k o
    gbeb     ctot   o      iofo
    h b      e t    m      n o
    t e      d o    e      d f
        calac                f
       calclac              faf
      calcuclac            fasaf
     calculuclac          fascsaf
    calculaluclac        fascicsaf
   calculataluclac      fascinicsaf
  calculatitaluclac    fascinanicsaf
 calculatioitaluclac  fascinatanicsaf
          c         fascinatedetanicsaf
          a                  f
          l                  a
          c                  s   m
          u                  c  mom
          l  h               i mosom
          a hah              nmostsom
          thasah             a   m o
          i  h               t   oofo
          o  a               e   s o
          n  s               d   t f

                r              t
               rir            tht
              rigir          thiht
             rigogir        thiniht
     W      rigorogir      thinkniht
    WeW    rigororogir    thinkekniht
   WeseW  rigorouorogir  thinkerekniht
 West'tseW      r              t
West's'tseW     i              h
  t  W          g              i
 tht e          o              n
thehts          r              k
  t  t          o              e
  h  '          u              r
  e  s          s              s

Notice that each word tree has a "trunk" consisting of the original word repeated twice vertically, and then "leaves" added to the top half of the trunk so that each level of leaves corresponds to an increasing portion of the word, repeated forwards and backwards and centered on the trunk. The tree for the word Since is shown at right.

The word trees are always planted in rows with an exact width of 40 characters. I plant the trees from left to right, placing each one as far to the left as I can without overlapping any previously planted tree. The ground consists of 40 = characters, and the maximum height of any tree is 23 characters (not including the ground).

The input will contain 5 lines of text. Each line of text will contain a list of words with each pair of words separated by a single space character. Each word will consist of a sequence of alphanumeric characters (and possibly also punctuation characters in some cases).

Each line of text should be turned into a line of trees, as described above. The ground should always have exactly 40 = characters. Each line of trees will always fit into a space of 24 rows by 40 columns.

Sample Input

Since the Greeks invented logic
and geometry the idea that all reasoning
might be reduced to some kind of
calculation has fascinated most of
the West's rigorous thinkers

Sample Output

See above. Note that each new row of trees should appear in the output window below the row before, not beside it as shown here. The rows are only shown side by side to save space.

Educational Computing Organization of Ontario - statements, test data and other materials can be found at


There are no comments at the moment.