Sorting Crayons
Time limit8sMemory limit1024 MB
Given strings of crayon types, the task is to sort each string so lowercase letters come first, then uppercase, then digits, each in ascending order.
- Level
Easy1 of 10
- Topics
- Sorting, Implementation
- Solved
- No attempts yet
Problem
Yokohama-kun has crayons in a case. Each crayon type is a single character: a lowercase English letter, an uppercase English letter, or a digit. The case may contain several crayons of the same type.
One day he lent the case to his family, and the crayons came back in a mixed order. Yokohama-kun likes neat arrangements, so he decided to reorder them in the following way.
- Lowercase letters are placed to the left of all uppercase letters, and uppercase letters are placed to the left of all digits.
- Among lowercase letters, the one earlier in alphabetical order is placed further left.
- Among uppercase letters, the one earlier in alphabetical order is placed further left.
- Among digits, the smaller digit is placed further left.
Find the order of the crayons after sorting.
Input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset is one line containing a string that represents the order of the crayons. The -th character of from the left is the type of the crayon at position from the left.
The length of is between 1 and 1,000, inclusive, and consists of lowercase English letters, uppercase English letters, and digits.
The end of the input is marked by a line containing only #. There are at most 50 datasets.
Output
For each dataset, output on one line the string that represents the order of the crayons after sorting.