(E) Mixed text

Goal: I will learn how to use iterators and algorithms of STL.

Instructions: Retrieve the code template: template/05/mixing_alphabets/ -> student/05/mixing_alphabets/.

According to a researcher (sic) at Cambridge University, it doesn’t matter in what order the letters in a word are, the only important thing is that the first and last letter be at the right place. The rest can be a total mess and you can still read it without problem. This is because the human mind does not read every letter by itself but the word as a whole.

The code template comprises iteration that reads text word by word and prints each word until ”END” is inputted. Insert code line(s) that mix(es) text according to the rule above.

In mixing, use STL algorithm shuffle and pseudorandom number generator generator declared in the first line of function main in the given code template. In this way, you can produce random numbers suitable for the automated tests.

Below you can see an example input given in a copy-paste way. The input takes 2 lines (including the line break at the end of the second line):

Enter some text. Quit by entering the word "END".
According to a researcher at Cambridge University it
does not matter in what order the letters in a word are END
Aonrcdicg
to
a
rcasheerer
at
Cabrmigde
Uvensriity
it
deos
not
maettr
in
what
oerdr
the
lettres
in
a
word
are

Tips for completing the assignment:

  • If the user interface of the program seems to work in a strange way, note that while structure is executed once for each given word. If you write a single word and press enter, while structure will be executed once. If you write a line with 5 words, while structure will be executed 5 times. Processing an input of 5 lines goes as follows. When executing while structure for the first time (for the first word), the rest 4 words are waiting for the next reading operation in the input buffer. In the above example, all the lines copied and pasted are in the input buffer waiting for the next reading operation.
  • If reading the input feels difficult, do not worry about it, you need not understand it. It is sufficient that you can write code that mixes one word in the right place in the code template.

A+ presents the exercise submission form here.