The sword refers to the source code of the offer series-string arrangement, and the sword refers to the offer

Source: Internet
Author: User

The sword refers to the source code of the offer series-string arrangement, and the sword refers to the offer

Question 1369: String sorting time limit: 1 second memory limit: 32 MB special question: No submitted: 2432 solution: 609 question Description: enter a string, print all characters in the string in Lexicographic Order. For example, if abc is input, all the strings abc, acb, bac, bca, cab, and CBA that can be arranged by characters a, B, and c are printed. Input: each test case contains one line. Enter a string of no more than 9 characters (repeated characters may exist), including only uppercase and lowercase letters. Output: corresponding to each group of data, all data is output in Lexicographic Order. Sample input: abcBCA sample output: abcacbbacbcacabcbaABCACBBACBCACABCBA

# Include <stdio. h> # include <stdlib. h> # include <string. h> void bubbleSort (char * arr, int begin, int length); void swap (char * a, char * B); void Permulation (char * arr, int k, int length); int main () {char arr [10]; int length; int I; while (gets (arr) {length = strlen (arr); bubbleSort (arr, 0, length); Permulation (arr, 0, length);} return 0;} void Permulation (char * arr, int k, int length) {int I; if (k = length) {for (I = 0; I <length; I ++) printf ("% c", arr [I]); printf ("\ n ");} else {for (I = k; I <length; I ++) {if (k! = I & arr [k] = arr [I]) continue; swap (& arr [k], & arr [I]); bubbleSort (arr, k + 1, length); Permulation (arr, k + 1, length); bubbleSort (arr, k + 1, length) ;}} void swap (char * a, char * B) {char c; c = * B; * B = * a; * a = c;} // bubble sort void bubbleSort (char * arr, int begin, int length) {int I, j; for (I = begin; I <length; I ++) {for (j = I + 1; j <length; j ++) {if (arr [I]> arr [j]) {swap (& arr [I], & arr [j]) ;}}}

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.