Car License Plates
InterviewTime limit2sMemory limit1024 MB
Given a valid Russian plate (letter, three digits, two letters), list every distinct plate formed by permuting its three digits and its three letters.
- Level
Medium4 of 10
- Topics
- Combinatorics, Implementation, Hash map, String
- Solved
- No attempts yet
Problem
When investigating traffic accidents, finding a car whose driver left the scene is often a problem.
Getting witness testimony is not easy work. The situation is made harder by the fact that witnesses very often remember the car's plate only approximately. On top of that, the person being questioned may well mix up the order of the digits or letters in the plate.
Given a plate obtained from an accident witness, count how many different plates can be formed from it by rearranging letters, digits, or both, and output all such plates.
Recall that car plates in Russia consist of three letters and three digits arranged as follows: one letter, three digits, then two letters. We ignore the part of the plate that identifies the region where the car is registered.
The following letters may be used in a plate: <<A>>, <<B>>, <<C>>, <<E>>, <<H>>, <<K>>, <<M>>, <<O>>, <<P>>, <<T>>, <<X>>, <<Y>> (these letters have visually similar counterparts in both the Russian and Latin alphabets). In this problem the input file uses Latin alphabet letters.
Input
The input file contains a single line, which is a valid car plate.
Output
In the first line of the output file, print the number , the count of plates that can be formed from the given one by rearranging letters, digits, or both.
In the following lines, print all such plates in any order.