What Does the Cow Say?

What Does the Cow Say?

The original Cowsays are written in the Perl programming language, and as such are easily adaptable to system tasks in Unix. They can perform functions such as telling users their home directories are full, that they have new mail, etc. Now you will write your own realization for this classic unix program. This concept can teach you how to prepare and format text for the console output.

Our cow is young and can only say some of the words we teach it. Not only does it talk, but this cow can turn into the famous Tux (wiki/Cowsay) if we ask it nicely.

You are given some text and your function should format it in the "cows" speech. Let's examine the rules for this problem:
  • The cow is always the same, only quote changes.
  • Multiple spaces in a row are replaced by one space.
  • The top border consists of underscore characters. It starts from a single space and ends before the border column. ...
  • If the line is greater than or equal to 40 characters, it should be split by these rules:
    • Max line size is 39 chars. If any spaces are in the line, split it by the rightmost space (this space is removed from text) otherwise take the first 39 characters.
    • After the split align all lines to same length by adding spaces at the end of each line.
    • First line borders: /\
    • Middle line borders: ||
    • Last line borders: \/
  • The bottom border consists of the minus sign. Has same length as top.
  • cowsay console program has strange behavior in certain cases, this cases will not be tested here.
You should be an authorized user in order to see the full description and start solving this mission.