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(a,a+n)也能过,只要对字符串进行处理比如说开一个int数组,把'A'转为1,'a'转为2,'B'转为3... 总之大写转偶数序列,小写转奇数(一一对应) 每next_permutation(a,a+n)一次就把int转成字符串输出(还是那个法则,只不过逆了过来) #include <stdio.h> #include <stdlib.h> #include <string.h> #include <algorithm> using namespace std; char a[15]; int b[15]; int cmp ( const void *a , const void *b ) { return *(int *)a - *(int *)b; } void change1() { int n,i; n=strlen(a); for(i=0;i<=n-1;i++) { if(a[i]>='A' && a[i]<='Z') { b[i]=2*(a[i]-'A')+1; } else if(a[i]>='a' && a[i]<='z') { b[i]=2*(a[i]-'a')+2; } } } void change2(int n) { int i; for(i=0;i<=n-1;i++) { if(b[i]%2==1) { a[i]=(b[i]-1)/2+'A'; } else if(b[i]%2==0) { a[i]=(b[i]-2)/2+'a'; } } } int main() { int t; int n; scanf("%d",&t); while(t--) { scanf("%s",a); n=strlen(a); change1(); qsort(b,n,sizeof(b[0]),cmp); do { change2(n); printf("%s\n",a); }while(next_permutation(b,b+n)); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator