user-0 提问: 求高手帮解决这个问题，用C语言

回复:
user: user-1
content: 其实就枚举一下排列 int a[10],vis[10]; void check_print(){     // 0/12 + 3/45 = 6/78     int den12=a[1]*10+a[2],         den45 =a[4]*10+a[5],         den78 =a[7]*10+a[8];      if((a[0]*den45+a[3]*den12)*den78==a[6]*den12*den45)         printf("%d/%d+%d/%d=%d/%d\n",a[0],den12,a[3],den45,a[6],den78); }  void dfs(int d){     if(d==9) return check_print();     for(int i=1;i<10;i++) if(!vis[i]){         vis[i] =1;         a[d] =i;         dfs(d+1);         vis[i] =0;     } }  //call dfs(0)

user: user-2
content: //共有16个组合 #import <Foundation/Foundation.h>  //得到分数和组成分数的3个数 typedef struct number{     float num;     int a;     int b;     int c; }Number;  int main(int argc, const char * argv[]) {     //504，是因为C(9, 3)*6 = 504     Number numb[504] = {0};     int a[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9};     int *p = a;     int e = 0;     //得到所有分数     for (int i = 0; i < 9; i++) {         for (int j = 0; j < 9; j++) {             for (int k = 0; k < 9; k++) {                 if (j != i && k != i && k != j) {                     //分子                     float molecular = *(p + i);                     //分母                     int denominator = *(p + j) * 10 + *(p + k);                     //将分数和构成分数的3个数存储到结构体中                     numb[e].num = (molecular / denominator);                     numb[e].a = *(p + i);                     numb[e].b = *(p + j);                     numb[e].c = *(p + k);                     //计算分数的个数                     e++;                 }             }         }              }     //确认下组成的分数是不是504个     printf("\n%d\n", e);     Number *p1 = numb;     //计数，看有几组这样的数     int count = 0;     for (int i = 0; i < 504; i++) {         for (int j = 0; j < 504; j++) {             if (j != i) {                 for (int k = 0; k < 504; k++) {                     if (k != i && k !=j) {                                                  //判断3个分数的组合是否满足题意                         BOOL Y = (p1 + i)->num + (p1 + j)->num == (p1 + k)->num;                         if (Y == 1) {                             //排除符合等式，但1~9重复用得组合                             BOOL Y1 = (p1 + j)->a ==(p1 + i)->a|| (p1 + j)->b == (p1 + i)->a||(p1 + j)->c == (p1 + i)->a;                             BOOL Y2 = (p1 + k)->a ==(p1 + i)->a|| (p1 + k)->b == (p1 + i)->a||(p1 + k)->c == (p1 + i)->a;                                                          BOOL Y3 = (p1 + j)->a ==(p1 + i)->b|| (p1 + j)->b == (p1 + i)->b||(p1 + j)->c == (p1 + i)->b;                             BOOL Y4 = (p1 + k)->a ==(p1 + i)->b|| (p1 + k)->b == (p1 + i)->b||(p1 + k)->c == (p1 + i)->b;                                                          BOOL Y5 = (p1 + j)->a ==(p1 + i)->c|| (p1 + j)->b == (p1 + i)->c||(p1 + j)->c == (p1 + i)->c;                             BOOL Y6 = (p1 + k)->a ==(p1 + i)->c|| (p1 + k)->b == (p1 + i)->c||(p1 + k)->c == (p1 + i)->c;                                                          BOOL Y7 = (p1 + j)->a ==(p1 + k)->a|| (p1 + j)->b == (p1 + k)->a||(p1 + j)->c == (p1 + k)->a;                             BOOL Y8 = (p1 + j)->a ==(p1 + k)->b|| (p1 + j)->b == (p1 + k)->b||(p1 + j)->c == (p1 + k)->b;                             BOOL Y9 = (p1 + j)->a ==(p1 + k)->c|| (p1 + j)->b == (p1 + k)->c||(p1 + j)->c == (p1 + k)->c;                                                          BOOL Y10 = Y1 || Y2 || Y3 || Y4 || Y5 || Y6 || Y7 || Y8 || Y9;                             if (Y10 != 1) {                                 //打印符合要求的组合                                 printf("(%f,%d,%d,%d)\n", (p1 + i)->num, (p1 + i)->a, (p1 + i)->b, (p1 + i)->c);                                 printf("(%f,%d,%d,%d)\n", (p1 + j)->num, (p1 + j)->a, (p1 + j)->b, (p1 + j)->c);                                 printf("(%f,%d,%d,%d)\n", (p1 + k)->num, (p1 + k)->a, (p1 + k)->b, (p1 + k)->c);                                 printf("\n");                                                                  count++;                             }                         }                     }                 }             }         }     }     printf("总共有%d组合\n", count);          return 0; }

user: user-2
content: //总共有11194组合 #import <Foundation/Foundation.h>  //得到分数和组成分数的3个数 typedef struct number{     float num;     int a;     int b;     int c; }Number;  int main(int argc, const char * argv[]) {     //504，是因为C(9, 3)*6 = 504     Number numb[504] = {0};     int a[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9};     int *p = a;     int e = 0;     //得到所有分数     for (int i = 0; i < 9; i++) {         for (int j = 0; j < 9; j++) {             for (int k = 0; k < 9; k++) {                 if (j != i && k != i && k != j) {                     //分子                     float molecular = *(p + i);                     //分母                     int denominator = *(p + j) * 10 + *(p + k);                     //将分数和构成分数的3个数存储到结构体中                     numb[e].num = (molecular / denominator);                     numb[e].a = *(p + i);                     numb[e].b = *(p + j);                     numb[e].c = *(p + k);                     //计算分数的个数                     e++;                 }             }         }              }     //确认下组成的分数是不是504个     printf("\n%d\n", e);     Number *p1 = numb;     //计数，看有几组这样的数     int count = 0;     for (int i = 0; i < 504; i++) {         for (int j = 0; j < 504; j++) {             if (j != i) {                 for (int k = 0; k < 504; k++) {                     if (k != i && k !=j) {                         //判断3个分数的组合是否满足题意                         BOOL Y = (p1 + i)->num + (p1 + j)->num == (p1 + k)->num;                         if (Y == 1) {                             printf("(%f,%d,%d,%d)\n", (p1 + i)->num, (p1 + i)->a, (p1 + i)->b, (p1 + i)->c);                             printf("(%f,%d,%d,%d)\n", (p1 + j)->num, (p1 + j)->a, (p1 + j)->b, (p1 + j)->c);                             printf("(%f,%d,%d,%d)\n", (p1 + k)->num, (p1 + k)->a, (p1 + k)->b, (p1 + k)->c);                             printf("\n");                                                          count++;                         }                     }                 }             }         }     }     printf("总共有%d组合\n", count);          return 0; }

user: user-3
content: 用递归得到所有排列， 对每种排列判断是否满足条件。  #include <iostream> #include <algorithm> //std::swap  bool judge(int(&vec)[9]){ 	//vec[2]/(10*vec[0] + vec[1]) + vec[5]/(10*vec[3] + vec[4]) = vec[8]/(10*vec[6] + vec[7])    int left  = (10* vec[0]+vec[1])*(10*vec[3] + vec[4])*vec[8];    int right = (10*vec[6] + vec[7]) * ( vec[2]*(10*vec[3] + vec[4] )+vec[5] * (10*vec[0]+vec[1])) ;    return left == right;	 } inline  void solve_aux(int(&vec)[9], int level) {   if(level < 1){      if(judge(vec)){        int i = 0;        for(; i + 1 < 9; ++i){          std::cout << vec[i] << ",";        }         std::cout << vec[i] <<std::endl;      }   }else{       for(int i = 0; i < level; ++i){          std::swap(vec[i], vec[level-1]);          solve_aux(vec,level-1);          std::swap(vec[i], vec[level-1]);       }   } }  inline  void solve(int(&vec)[9]) {    solve_aux(vec, 9);	 }  int main(){    int vec[] = { 1,2,3,4,5,6,7,8,9 };    solve(vec);     return 0;	 }   //vec[2]/(10*vec[0] + vec[1]) + vec[5]/(10*vec[3] + vec[4]) = vec[8]/(10*vec[6] + vec[7]) 5,6,4,9,8,7,2,1,3 9,8,7,5,6,4,2,1,3 2,6,5,7,8,9,1,3,4 7,8,9,2,6,5,1,3,4 7,8,5,2,6,1,3,9,4 2,6,1,7,8,5,3,9,4 4,8,7,9,6,1,3,2,5 9,6,1,4,8,7,3,2,5 3,4,9,6,8,2,1,7,5 6,8,2,3,4,9,1,7,5 9,6,7,3,2,1,4,8,5 3,2,1,9,6,7,4,8,5 3,9,4,7,8,1,5,2,6 7,8,1,3,9,4,5,2,6 5,1,9,6,8,2,3,4,7 6,8,2,5,1,9,3,4,7 9,6,5,3,2,1,8,4,7 3,2,1,9,6,5,8,4,7 3,4,6,5,1,8,2,7,9 5,1,8,3,4,6,2,7,9

user: user-4
content: 首先九次循环遍历出所有分数和相同的情况 然后再选出九次循环都不想等的情况 具体怎么实现自己想吧