再问一下
一楼给出的程序
数组a内的元素都是唯一不重复的么
一楼给出的程序
数组a内的元素都是唯一不重复的么
Only the Code Tells the Truth K.I.S.S
#include <stdio.h> #include <string.h> #define N 5 #define M 3 #define SWAP(x, y, t) ((t) = (x), (x) = (y), (y) = (t)) void foo(char* s, int from, int to); int main(void) { char str[2 * N - M + 1] = "12345"; char s[M + 1] = {0}; int i, j; for(i = N, j = 0; i < N + M - 1; i++, j++) str[i] = str[j]; puts(str); for(i = 0; i < N; i++) { for(j = i; j < i + M; j++) { s[j - i] = str[j]; } foo(s, 0, strlen(s) - 1); } putchar('\n'); return 0; } void foo(char *s, int from, int to) { int i, j, t; if(to <= 1) return; if(from == to) { for(i = 0; i <= to; i++) putchar(s[i]); putchar('\t'); } else { for(j = from; j <= to; j++) { SWAP(s[j], s[from], t); foo(s, from + 1, to); SWAP(s[j], s[from], t); } } }