Is Tencent 2011 years of Pen test, I did not read the answer, I think of the stupid way, is literally, that
All possible permutations are first calculated, and then the calculation of each permutation is divisible by 7.
The key is to generate all permutations, fortunately studied the scheme language, the recursive has the experience, the code is as follows
#include <iostream> #include <stdio.h> using namespace std;
int Calc (char *p_base_addr, char base_len) {int res = 0, radix = 1;
for (int i = base_len-1; I >=0; radix *=, i--) {res + = radix * P_base_addr[i];
} return res; } void Print_res (char *p_base_addr, char Base_len) {for (int i = 0; i < Base_len; i++) {printf ("%d",
P_base_addr[i]);
} printf ("\ n");
} void Swap_f (char *p1, char *p2) {char temp = *P1;
*P1 = *P2;
*P2 = temp; } void Find7 (char *p_base_addr, Char Base_len, Char *p_cur_addr, char cur_len) {if (Cur_len = = 1) {int
res = Calc (p_base_addr, Base_len);
if (res% 7 = = 0) {printf ("==>");
} print_res (P_base_addr, Base_len);
}else{for (int i = 0; i < Cur_len; i++) {Swap_f (&p_cur_addr[0], &p_cur_addr[i]);
Find7 (P_base_addr, Base_len, p_cur_addr+1, cur_len-1); Remember to swap back!
Swap_f (&p_cur_addr[0], &p_cur_addr[i]);
}}} int main () {char a[4] = {1, 2, 3, 4};
Find7 (A, 4, a, 4);
return 0;
}