UVA 10098 generating Fast (full array)

Source: Internet
Author: User

Or the two methods, recursion and STL, recursive that is the full array of repeating elements, the problem I did not try to not repeat the elements of the arrangement, because from the topic did not find that there must be duplicate elements ()

Post code:

<span style= "Font-family:courier new;font-size:18px;" > #include <stdio.h> #include <string.h> #include <stdlib.h> #include <algorithm>using Namespace Std;int cmp (const void *a,const void *b) {return * (char *) A-* (char *) b;} int main () {int T;char a[15];scanf ("%d", &t), while (t--) {scanf ("%s", a); int len = strlen (a); Qsort (A,len,sizeof (a[0]) , CMP);p UTS (a); while (Next_permutation (A,a+len)) {puts (a);} Puts ("");} return 0;} </span>
recursion:

<span style= "Font-family:courier new;font-size:18px;" > #include <stdio.h> #include <string.h> #include <stdlib.h>int cmp (const void *a,const void *b) { return * (char *) A-* (char *) b;} void Solve (int len,char *a,char *b,int cur) {int i,j;if (cur = = len) {puts (b); return;} Else{for (i=0; i<len; i++) {if (!i| | (A[i]! = a[i-1]))  {int ans1 = 0, Ans2 = 0;for (j=0; j<len; j + +) if (a[i] = = A[j]) ans1++;for (j=0; j<cur; j + +) if (B[j]==a[i]) ans2++;if (ans2 < ans1) {B[cur] = A[i];solve (Len, A, B, cur+1);}}} return;} int main () {int T;char A[15];char b[15];scanf ("%d", &t), while (t--) {memset (A, ' ', sizeof (a)), memset (b, ' n ', sizeof (b)); scanf ("%s", a), int len = strlen (a), Qsort (A,len,sizeof (a[0]), CMP), Solve (len,a,b,0);p UTS ("");} return 0;} </span>



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

UVa 10098 generating Fast (fully arranged)

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.