Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
但我想用这个……In Reply To:next_permutation 过了 Posted by:speedcell4 at 2011-03-29 14:24:26 #include<iostream> #include<cstring> using namespace std; char a[200],now[200],last[200]; int v[200]={0}; int cmp(const void *a,const void *b) { return *(char *)a-*(char *)b; } void kan(int n,int l) { if(l==n&&strcmp(now,last)>0) { for(int i=0;n-i;i++) { cout<<now[i]; last[i]=now[i]; } cout<<endl; } else { for(int i=0;n-i;i++) { if(v[i]==0) { v[i]=1; now[l]=a[i]; kan(n,l+1); v[i]=0; } } } } int main() { gets(a); qsort(a,strlen(a),sizeof(char),cmp); kan(strlen(a),0); } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator