Full sorting of questions (0th questions of the 1st session) and 1 question of The 0th session

Source: Internet
Author: User

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.

 

Related Article

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.