void perm_alphametic(int arr[], int len, int n, int k) { int i; if (len == k) { if (check_alphametic(arr)) print_arr(arr, len); return; } for (i = len; i < n; i++) { swap_arr(arr, i, len); perm_alphametic(arr, len + 1, n, k); swap_arr(arr, i, len); } }
void swap_rotate(char *arr, int rotate_index, int arr_size) { //deal with the most simplest case if (arr_size <= 1 || rotate_index <= 0) { return ; } //确定要交换的向量a[m],b[n] char *a = arr; char *b = a + rotate_index; int m = rotate_index; int n = arr_size - m; p_arr(a, m); p_arr(b, n); //确定用来进行对等交换的向量p[min], q[min] char *p; char *q; int min; min = (m <= n ? m : n); if (m <= n) { p = a; q = b + n - min; //b + (n - 1) - (min - 1); } else { p = b; q = a; } //交换向量 p,q swap_arr(p,q,min); p_arr(arr, arr_size); //确定新的arr, rotate_index, arr_size //上面的三个参数需要a[m], b[n]来确定 char * arr_new; int rotate_index_new; int arr_size_new; if (m <= n) { arr_new = a; arr_size_new = arr_size - min; rotate_index_new = min; } else { arr_new = a + min; arr_size_new = arr_size - min; rotate_index_new = arr_size_new - min; } printf("rotate_index_new = %d, arr_size_new = %d\n", rotate_index_new, arr_size_new); p_arr(arr_new, arr_size_new); swap_rotate(arr_new, rotate_index_new, arr_size_new); }
void swap_u64_arr(uint64_t arr[], int arr_size) { swap_arr(arr, arr_size); }
void swap_int_arr(uint32_t arr[], int arr_size) { swap_arr(arr, arr_size); }
void swap_short_arr(uint16_t arr[], int arr_size) { swap_arr(arr, arr_size); }
void swap_byte_arr(uint8_t arr[], int arr_size) { swap_arr(arr, arr_size); }