Frequent Suffixes X87028


Statement
 

pdf   zip

thehtml

Write a program that reads a sequence of words, and groups them by their 3-letters suffix.

For each 3-letter suffix seen in at least two different words in the sequence, the program must output the number of different words with that suffix, followed by the list of such words in alphabetical order.

The list of suffixes must also be sorted in alphabetical order.

Note that words with less than 3 letters do not have any 3-letter suffix.

Input The input is a sequence of words. They may be in different lines, and have a varying number of whitespaces inbetween. All words are in lowercase. There are only letters and whitespaces in the sequence.

Output The output is a list of 3-letter suffixes in alphabetical order. For each suffix, the number of different of seen words with that suffix is printed, followed by the list of those words, also in alphabetical order.

Follow the format in the examples.

Public test cases
  • Input

    the cat sat on the mat
    my friend pat had a chat with his sister kat
    this is the beginning of the end
    

    Output

    end: 2 end friend
    his: 2 his this
    
  • Input

    crocodrile
    pterodactile chicken reptile
    ken barbie
    barbie barbie flinch pinch barbie hen pen when
    

    Output

    hen: 2 hen when
    ile: 3 crocodrile pterodactile reptile
    ken: 2 chicken ken
    nch: 2 flinch pinch
    
  • Input

    python is an interpreted high level general purpose programming language
    created by guido van rossum and first released in  pythons design
    philosophy emphasizes code readability with its notable use of
    significant whitespace  its language constructs and object oriented
    approach aim to help programmers write clear logical code for small
    and large scale projects 
    
    python is dynamically typed and garbage collected
    it supports multiple programming paradigms including
    procedural object oriented and functional programming
    python is often described as a batteries included
    language due to its comprehensive standard library 
    
    python was conceived in the late s as a successor to the abc language
    python   released in  introduced features like list comprehensions
    and a garbage collection system capable of collecting reference
    cycles  python   released in  was a major revision of the
    language that is not completely backward compatible and much
    python  code does not run unmodified on python  
    
    python interpreters are available for many operating systems
    a global community of programmers develops and maintains cpython
    an open source reference implementation  a non profit organization
    the python software foundation manages and directs resources for
    python and cpython development 
    

    Output

    age: 2 garbage language
    ard: 2 backward standard
    are: 2 are software
    ble: 4 available capable compatible notable
    cts: 3 constructs directs projects
    ers: 2 interpreters programmers
    hon: 2 cpython python
    ing: 4 collecting including operating programming
    ion: 5 collection foundation implementation organization revision
    ity: 2 community readability
    ons: 2 comprehensions pythons
    ral: 2 general procedural
    ted: 4 collected created interpreted oriented
    
  • Information
    Author
    Language
    English
    Official solutions
    Python
    User solutions
    Python