Please write in C++ a solution to the following problem. Having a list of words (which are sequences of small letters), one word per one line, sort them according to the following order: word_1 is smaller that word_2 if word_1 contains more letters ‘a’, and in the case of the equal number of ‘a’ letters in both words, consider the number of letter ‘b’, and as a smaller word take word with bigger number of letter ‘b’, and so on. In the case of two words have the same number of equivalent letters, take into account lexicographic order between them. For example: baabca is bigger that ccaaaa (3 x ‘a’ vs 4 x ‘a’), and xababx is smaller than abacd (2 x ‘a’ in both words, but 2 x ‘b’ in the first one vs 1 x ‘b’ in the second one word). Word bbaaxx is smaller than xxaabb. An example input and output. Input: ale james john ela alexander kamil Output: alexander james ale ela kamil john
Comments
Leave a comment