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 |
why --------- ! [ s[len] = 0; ] -------- WA, --or---AC???????????????????????????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; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator