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 + compare函数水过#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator