#ACSL2021S2. ACSL2021S2

ACSL2021S2

PROBLEM: Transform a given string by first keeping just the alphanumeric characters (i.e. 0-9, A-Z, a-z). Sort the remaining letters and then rear range the repeated blocks of letters such that the longer blocks come first. Within blocks of the same length, the first block is sorted in ascending order; the next block, in descending order; then ascending order; and so on. Finally, change it to compressed form by printing the size of each block followed by the characters for that size. Use a comma to separate each differently-sized block.

For example, in the string "This is an Example of Sorting an interesting string", create the result as follows:

Sorted order: ESTaaaeeefggghiiiiiilmnnnnnnooprrrssssttttx

Blocks of 6: iiiiii nnnnnn

Blocks of 4: tttt ssss

Blocks of 3: aaa eee ggg rrr

Blocks of 2: oo

Blocks of 1: E S T f h l m p x

Printed format: 6in,4ts,3aegr,2o,1ESTfhlmpx

INPUT: Your program will receive a single line of data, each containing a single string. Ignore all spaces and non-alphanumeric characters. Each line will be no more than 100 characters.

OUTPUT: Print each input string in the rearranged order, as described above.

INPUT:

This is an Example of Sorting an interesting string
HackerRank.com was used for the ACSL Finals this year.
The digits of PI are 3.141592653.
She sells seashells by the seashore.
Programming languages include Java, Python, C++, Visual BASIC, Ruby, and Scratch.

OUTPUT:

6in,4ts,3aegr,2o,1ESTfhlmpx
5a,4se,3r,2tonkihc,1ACFHLRSdflmuwy
2135ei,1tsrohgfdaTPI9642
7es,4lh,2a,1ytrobS
8a,5n,4gu,3rlic,2CPSdehmosty,1vbVRJIBA