紫书 习题2-6 排列
1 #include <stdio.h> 2 #include <string.h> 3 4 int main() 5 { 6 int i, count = 0, j, k, a[10], c;//用i表示abc,j表示def,k表示ghi 7 memset(a, 0, sizeof(a));//初始化数组,全部为零 8 for ( i=123; i<=329; i++ ) 9 { 10 j = i*2; 11 k = i*3; 12 a[i/100] = a[i/10%10] = a[i%10] = 1;//分别标记出现过的数字 13 a[j/100] = a[j/10%10] = a[j%10] = 1; 14 a[k/100] = a[k/10%10] = a[k%10] = 1; 15 for ( c=0; c<10; c++ ) 16 count += a[c]; 17 if ( count == 9 ) //只有1到9每个数字被标记结果才为9 18 printf("%d\n%d\n%d\n", i, j, k); 19 count = 0; 20 memset(a, 0, sizeof(a)); 21 } 22 23 return 0; 24 }