#K2741. Canonical Phone Numbers
Canonical Phone Numbers
Canonical Phone Numbers
You are given a list of phone numbers. Your task is to convert each phone number into its canonical form according to the following rule:
If a phone number has at most 3 digits, it remains unchanged. Otherwise, you repeatedly take groups of 2 digits from the start until the remaining part has at most 3 digits. Then, append the remaining digits as the final group. All the groups are then joined with a '-' (hyphen).
For example:
- "1234567890" becomes "12-34-56-78-90"
- "987654321" becomes "98-76-54-321"
- "123" stays as "123"
Implement a program that reads the input from stdin (each line is a phone number) and outputs the corresponding canonical phone numbers to stdout, one per line. Ensure your solution handles various lengths correctly.
inputFormat
The input consists of several lines, each containing a single phone number (a string of digits). Empty lines should be ignored.
outputFormat
For each phone number from the input, output its canonical form on a new line. Do not output extra spaces or additional text.
## sample1234567890
987654321
0
12-34-56-78-90
98-76-54-321
0
</p>