Topic Requirements
Problem Description: Enter a possible duplicate of the English string (with a comma as the closing tag), in dictionary order without repeating all its possible permutations.
Sample Input 1:ABC,
Sample output 1:ABC ACB BAC BCA Cab CBA
Sample Input 2:cab,
Sample output 2:ABC ACB BAC BCA Cab CBA
Sample Input 3:abb,
Sample output 3:abb bab BBA
Solution Solutions
This problem is an all-in-one problem, and two questions need to be solved: first, the output is in dictionary order, and the second is no duplicate output. In order to guarantee the dictionary sequential output, the input string needs to be sorted first to facilitate subsequent operations. In order to ensure that there is no duplicate output, it is necessary to determine at the output whether the current situation is output, which is well judged in the context of the dictionary order.
In addition, an important idea of the whole arrangement is recursion. To calculate the full array of ABC, just let a first, then calculate the full order of the BC, and then output with a, then let B head, calculate the full array of AC, and finally let C-led, calculate AB's full array. Each letter is headed to the corresponding initial state, with ABC as an example, and its invocation status is as follows:
Source code Example
results show
Summary
The key is to arrange the back of the first, and then arrange the front. Note The For loop is used in conjunction with recursion.
The question of the whole arrangement (No. 0 session, title 1th)