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 |
next_permutation(s,s+len,mycompare)In Reply To:What is wrong with this code ? Posted by:temper_3243 at 2005-07-31 23:44:19 > I tried many times but it didn't work. This code works perfectly alright with the test data. If anyone could give me more test data it would be great. > > I first tried with standard sort but then assumed that for the string AaB i should permute AaB not ABa. So changed my sort comparision function. > > Regards, > Trry > temper_3243@yahoo.com > > #include<iostream> > #include<algorithm> > #include<cstdio> > #include<cstring> > #include<cctype> > using namespace std; > > int mycompare(char a,char b) > { > char c,d; > c=tolower(a); > d=tolower(b); > > if(c==d) > return (a<b); > > return c<d; > } > > int main() > { > int n,i; > scanf("%d",&n); > for(i=0;i<n;i++) > { > char s[16]; > scanf("%s",s); > int len=strlen(s); > sort(s,s+len,mycompare); > int j; > do{ > for(j=0;j<len;j++) > { > printf("%c",s[j]); > } > printf("\n"); > }while(next_permutation(s,s+len)); > > } > return 0; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator