The question of the whole arrangement (No. 0 session, title 1th)

Source: Internet
Author: User
Tags closing tag

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.