Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

next_permutation(s,s+len,mycompare)

Posted by frkstyc at 2005-07-31 23:45:41 on Problem 1256
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator