#C14237. Frequency Analysis and Bar Chart

    ID: 43864 Type: Default 1000ms 256MiB

Frequency Analysis and Bar Chart

Frequency Analysis and Bar Chart

You are given a block of text. Your task is to perform a frequency analysis of the words in the text and then display a horizontal bar chart representing the number of occurrences for each word.

Specifications:

  • Convert all words to lower case so that "Word", "word", and "WORD" are considered the same.
  • Remove all punctuation symbols (for example, commas, periods, exclamation marks, etc.).
  • Count the frequency of each distinct word in the text.
  • Sort the words by descending frequency. In case of a tie, the word that appears earlier in the text should come first.
  • Output two sections: the first shows a frequency table with two columns (Word and Frequency), and the second shows a horizontal bar chart where each bar is made of asterisks (*). The bar length corresponds to the frequency of the word.</p>

    The header of the frequency table should be displayed as:

    Word Frequency\texttt{Word Frequency}

    Each word in the frequency table should be left aligned in a field of width 12, and in the bar chart the word is left aligned in a field of width 8 followed by ' | ' and then its corresponding number of asterisks.

    inputFormat

    The input consists of a single text block provided via standard input (stdin). The text may span multiple lines and contains alphabets, punctuation, and spaces.

    outputFormat

    The output should have two sections. The first section is a frequency table with a header "Word Frequency" and then each word along with its count, each in a new line. This is followed by a blank line and then by the horizontal bar chart which starts with the header "Horizontal Bar Chart:" and then one line per word showing the word (left aligned in a field of 8), the string ' | ', and a series of asterisks corresponding to the word's frequency.## sample

    Hello world! This is an example example text. Hello again, world world world!
    Word         Frequency
    

    world 4 hello 2 example 2 this 1 is 1 an 1 text 1 again 1

    Horizontal Bar Chart: world | **** hello | ** example | ** this | * is | * an | * text | * again | *

    </p>