求求大佬们,帮我看一下这道题
Input第一行输入一个T代表有T组测试数据。
每组测试数据输入n,m。
Output
每个人得到的金额。注意行末换行。
#include <stdio.h> #include <stdlib.h> #include <math.h> #define TOKEN "X" //end of TOKEN #define Lovely_Elean_Formula "1"TOKEN"10"TOKEN"3"TOKEN"3.33"TOKEN //4 future doing //#define Grandpa_V_Formula "128"TOKEN"e"TOKEN"980"TOKEN"2116"TOKEN static int rrem[32]; void* f_add(void *x, void *y, unsigned char type) { void *ret = rrem; #define V_CHR 0 #define V_INT 1 #define V_FLT 2 #define V_DBL 3 #define LOG_SYM(_s) putchar(_s); #define LOG_SYM_ADD LOG_SYM('+') LOG_SYM_ADD; switch (type) { #define ADD_S + #define cast2type_add(_r, _x, _y, _t) \ *(_t *)(_r) = *(_t *)(_x) ADD_S *(_t *)(_y) case V_CHR: cast2type_add(ret, x, y, char); break; case V_INT: cast2type_add(ret, x, y, int); break; case V_FLT: cast2type_add(ret, x, y, float); break; case V_DBL: cast2type_add(ret, x, y, double); break; } return ret; } void* f_sub(void *x, void *y, unsigned char type) { void *ret = rrem; #define LOG_SYM_SUB LOG_SYM('-') LOG_SYM_SUB; switch (type) { #define SUB_S - #define cast2type_sub(_r, _x, _y, _t) \ *(_t *)(_r) = *(_t *)(_x) SUB_S *(_t *)(_y) case V_CHR: cast2type_sub(ret, x, y, char); break; case V_INT: cast2type_sub(ret, x, y, int); break; case V_FLT: cast2type_sub(ret, x, y, float); break; case V_DBL: cast2type_sub(ret, x, y, double); break; } return ret; } void* f_mul(void *x, void *y, unsigned char type) { void *ret = rrem; #define LOG_SYM_MUL LOG_SYM('*') LOG_SYM_MUL; switch (type) { #define MUL_S * #define cast2type_mul(_r, _x, _y, _t) \ *(_t *)(_r) = *(_t *)(_x) MUL_S *(_t *)(_y) case V_CHR: cast2type_mul(ret, x, y, char); break; case V_INT: cast2type_mul(ret, x, y, int); break; case V_FLT: cast2type_mul(ret, x, y, float); break; case V_DBL: cast2type_mul(ret, x, y, double); break; } return ret; } void* f_div(void *x, void *y, unsigned char type) { void *ret = rrem; #define LOG_SYM_DIV LOG_SYM('/') LOG_SYM_DIV; switch (type) { #define DIV_S / #define cast2type_div(_r, _x, _y, _t) \ *(_t *)(_r) = *(_t *)(_x) DIV_S *(_t *)(_y) case V_CHR: cast2type_div(ret, x, y, char); break; case V_INT: cast2type_div(ret, x, y, int); break; case V_FLT: cast2type_div(ret, x, y, float); break; case V_DBL: cast2type_div(ret, x, y, double); break; } return ret; } unsigned char* parse_expr(unsigned char *expr, int *vpos) { unsigned char *ret = (unsigned char *)rrem; while (expr) { *ret++ = *expr++; if ('X' == *expr) { //set tail *ret = 0; //return nwpos *vpos = ret - (unsigned char *)rrem + 1; return (unsigned char *)rrem; } } return (unsigned char *)rrem; } typedef void* (*math_fund)(void*, void*, unsigned char); static math_fund fund_tbl[4] = { f_add, f_sub, f_mul, f_div }; static char optr_tbl[4] = { '+', '-', '*', '/' }; enum Lv_Elean{EPA = 0, EPB, EPC}; int main(int argc, char *argv[]); int Miss_Eleans_puzzle_game(double *op, double res) { int i = 0; double v_exp; #define F_TBL_LEN sizeof(fund_tbl) / sizeof(fund_tbl[0]) #define USR_SCOUT_DEPTH 10 while (i++ < USR_SCOUT_DEPTH) { #define fund_idx(_i) (((unsigned char *)main)[_i] % 4) #define Lottery_A 39 #define Lottery_B 40 #define op_act_A (i + Lottery_A) #define op_act_B (i + Lottery_B) //#define PRINT_ON #ifdef PRINT_ON printf("optr1: %c, optr2: %c\n", optr_tbl[fund_idx(op_act_A)], optr_tbl[fund_idx(op_act_B)]); #endif puts("-----brute force start----"); v_exp = *(double *)fund_tbl[fund_idx(op_act_A)](&op[EPA], &op[EPB], V_DBL); printf("v_exp = %.2lf\n", v_exp); v_exp = *(double *)fund_tbl[fund_idx(op_act_B)](&v_exp, &op[EPC], V_DBL); printf("v_exp = %.2lf\n", v_exp); #define DIS 0.03 #define is_match(_exp) (fabs(_exp) < DIS) #ifdef PRINT_ON printf("i = %d, v_exp = %.10f\n", i, v_exp); #endif is_match(v_exp - res) ? puts("!!!!!!!Lottery Jackpot!!!!!!!") : puts("reward mismatch"); puts("-----brute force over-----"); puts(" "); } } int main(int argc, char *argv[]) { int of, inc = 0; double op[3], res; op[EPA] = atof(parse_expr(Lovely_Elean_Formula, &of)); inc += of; op[EPB] = atof(parse_expr(&Lovely_Elean_Formula[inc], &of)); inc += of; op[EPC] = atof(parse_expr(&Lovely_Elean_Formula[inc], &of)); inc += of; res = atof(parse_expr(&Lovely_Elean_Formula[inc], &of)); #ifdef PRINT_ON printf("EPA = %.2lf, EPB = %.2lf\n", op[EPA], op[EPB]); printf("EPC = %.2lf, res = %.2lf, of = %d\n", op[EPC], res, of); #endif Miss_Eleans_puzzle_game(op, res); return 0; }