4fd800b3a8 2011-02-23 kinaba: struct CountExpressions 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: static int add(int x, int y) { return x+y; } 4fd800b3a8 2011-02-23 kinaba: static int sub(int x, int y) { return x-y; } 4fd800b3a8 2011-02-23 kinaba: static int mul(int x, int y) { return x*y; } 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: int calcExpressions(int x, int y, int val) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: int num[][4] = { 4fd800b3a8 2011-02-23 kinaba: {x,x,y,y}, 4fd800b3a8 2011-02-23 kinaba: {x,y,x,y}, 4fd800b3a8 2011-02-23 kinaba: {x,y,y,x}, 4fd800b3a8 2011-02-23 kinaba: {y,x,x,y}, 4fd800b3a8 2011-02-23 kinaba: {y,x,y,x}, 4fd800b3a8 2011-02-23 kinaba: {y,y,x,x}, 4fd800b3a8 2011-02-23 kinaba: }; 4fd800b3a8 2011-02-23 kinaba: int (*op[])(int,int) = { &add, &sub, &mul }; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: int cnt = 0; 4fd800b3a8 2011-02-23 kinaba: for(int a=0; a<6; ++a) 4fd800b3a8 2011-02-23 kinaba: for(int i=0; i<3; ++i) 4fd800b3a8 2011-02-23 kinaba: for(int j=0; j<3; ++j) 4fd800b3a8 2011-02-23 kinaba: for(int k=0; k<3; ++k) 4fd800b3a8 2011-02-23 kinaba: if( val == op[k]( op[j]( op[i](num[a][0], num[a][1]), num[a][2] ), num[a][3] ) ) 4fd800b3a8 2011-02-23 kinaba: ++cnt; 4fd800b3a8 2011-02-23 kinaba: return cnt; 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: };