ls的效率真低
程序代码:
#include <stdio.h> #include <stdlib.h> int a[27] = {0}, begin, end; void dfs(int i, int len) { if (len == 0) { for (i = begin; i <= end; ++i) if (a[i]) putchar('a' + i - 1); putchar('\n'); } for (; i <= end; ++i) { if (a[i] == 0) { a[i] = 1; dfs(i + 1, len - 1); a[i] = 0; } } } int main(void) { int len; while (scanf("%d%d%d", &begin, &end, &len) != EOF) { int nlen; dfs(begin, len > (nlen = end - begin + 1) ? nlen : len); } return 0; }
starwing@starwing-desktop:~/test_c/bin$ echo '1 26 10' | time ./outcome > /dev/null
4.24user 0.02system 0:04.27elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+139minor)pagefaults 0swaps
starwing@starwing-desktop:~/test_c/bin$ echo '1 26 10' | time ./output > /dev/null
1.83user 0.01system 0:01.87elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+139minor)pagefaults 0swaps
4.24user 0.02system 0:04.27elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+139minor)pagefaults 0swaps
starwing@starwing-desktop:~/test_c/bin$ echo '1 26 10' | time ./output > /dev/null
1.83user 0.01system 0:01.87elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+139minor)pagefaults 0swaps