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 |
Re:递归,代码,此题坚决不用STL,那样太没意思In Reply To:递归,代码,此题坚决不用STL,那样太没意思 Posted by:smilerxz at 2009-08-12 15:59:26 > #include <iostream> > #include <algorithm> > using namespace std; > > #define MAXN 13 > > char a[MAXN + 1]; > int len; > char flag[MAXN]; > char s[MAXN + 1]; > > bool cmp(char a, char b) { > return tolower(a) == tolower(b) ? a < b : tolower(a) < tolower(b); > } > > void solve(int n) { > if (n == len) { > puts(s); > return; > } > for (int i = 0; i < len; i++) { > if (! flag[i]) { > flag[i] = 1; > s[n] = a[i]; > solve(n + 1); > flag[i] = 0; > while (i + 1 < len && a[i + 1] == a[i]) i++; > } > } > } > > int main() { > int CASE; > scanf("%d", &CASE); > while (CASE--) { > scanf("%s", a); > len = strlen(a); > sort(a, a + len, cmp); > memset(flag, 0, sizeof(flag)); > s[len] = 0; > solve(0); > } > return 0; > } 用stl不是超时就是超内存,过不去。。。反正就是最朴素的STL用法。。。 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator