Full sorting of questions (0th questions of the 1st session) and 1 question of The 0th session
Question requirements
Problem description: enterPossible repetitionEnglish string (with a comma as the end mark), PressDictionary orderNo possible arrangement is output repeatedly.
Example input 1: abc,
Sample output 1: abc acb bac bca cab CBA
Example input 2: cab,
Sample Output 2: abc acb bac bca cab CBA
Example input 3: abb,
Sample Output 3: abb bab bba
Solution
This problem is a full Sorting Problem, and two problems need to be solved: first, output in alphabetical order, and second, no repeated output. To ensure dictionary sequence output, you must first sort the input strings for subsequent operations. To ensure no repeated output, you need to determine whether the current situation has been output during the output, which is a good decision to ensure the dictionary order.
In addition, recursion is an important idea of full arrangement. To calculate the full arrangement of abc, we only need to let a first, then calculate the full arrangement of bc, and output it together with a. Then let B first, calculate the full arrangement of ac, and finally let c first, calculate the full arrangement of AB. After each letter is started, it must be restored to the corresponding initial state. Take abc as an example. Its call status is as follows:
Source code example
Result Display
Summary
The key to full arrangement is to recursively arrange the following, and then sort the previous one. Pay attention to the combined use of the for Loop and recursion.