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 + compare函数水过

Posted by hitfrank at 2010-04-26 14:39:51 on Problem 1256
#include <iostream>
#include <algorithm>
using namespace std;
bool cmp(const char &a, const char &b)
{
	if(a<='Z' && a>='A' && b<='Z' && b>='A')
		return a<b;
	if(a<='z' && a>='a' && b<='z' && b>='a')
		return a<b;
	if(a<='Z' && a>='A' && b<='z' && b>='a')
			return a+'a'-'A'<=b;
	if(a<='z' && a>='a' && b<='Z' && b>='A')
			return a<b+'a'-'A';
}
int main()
{
	char mem[20];
	int casenum;
	cin>>casenum;
	while(casenum--)
	{
		scanf("%s",mem);
		int len=strlen(mem);
		sort(mem,mem+len,cmp);
		do{
			printf("%s\n",mem);
		}while(next_permutation(mem,mem+len,cmp));
	}
	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