偶是一只想要飞却忘了咋飞的菜鸟
多谢大家了,快点告诉我
#include <iostream> #include <cmath> #include <cstdlib> #include <algorithm> using namespace std;
int main() { int code[9] = {1,2,3,4,5,6,7,8,9}; int num[9] = {0};
sort(code, code+9); do { bool success = false; for(int i = 1; i<9; i++) { num[i] = 0; for(int k = 0; k<=i; k++) { num[i] += code[k]*pow(10, (i-k)); } if(num[i]%(i+1) == 0) success = true; else { success = false; break; } } if(success) { for(int r = 0; r<9; r++) cout<<code[r]<<" "; cout<<endl; } }while (next_permutation(code, code+9));
system("pause"); return 0; }