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 |
329ms...这题输出要不少时间吧?dfs#include <iostream> #include <stdio.h> #include <string.h> using namespace std; int toNum(char c){ if(c >= 'A' && c <= 'Z') return 2 * (c-'A'); if(c >= 'a' && c <= 'z') return 2 * (c-'a') + 1; return -1; } char toChar(int q){ if(q%2==0) return q/2 + 'A'; return q/2 + 'a'; } void dfs(int *gs, int *rec, int len, int rem){ if(rem == 0){ for(int i = 0; i < len; i++){ printf("%c", toChar(rec[i])); } printf("\n"); return; } for(int i = 0; i < 52; i++){ if(gs[i] == 0) continue; gs[i]--; rec[len-rem] = i; dfs(gs, rec, len, rem-1); gs[i]++; } } int main() { int cases; scanf("%d", &cases); for(int ii = 0; ii < cases; ii++){ char s[16]; scanf("%s", s); int len = strlen(s); int gs[52] = {0}; int rec[14]; for(int i = 0; i < len; i++){ gs[toNum(s[i])] ++; } dfs(gs, rec, len, 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