#include <stdio.h> #include <stdbool.h> #include <string.h> char sign[3]; int num[4]; int sum = 0; int left = 4; // 判断是否可以通过某种运算组合得到 24 bool calculate(int card[]) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (j == i) continue; for (int k = 0; k < 4; k++) { if (k == i || k == j) continue; for (int l = 0; l < 4; l++) { if (l == i || l == j || l == k) continue; int tempCard[4] = {card[i], card[j], card[k], card[l]}; for (int op1 = 0; op1 < 4; op1++) { for (int op2 = 0; op2 < 4; op2++) { for (int op3 = 0; op3 < 4; op3++) { int tempSum = tempCard[0]; switch (op1) { case 0: tempSum += tempCard[1]; break; case 1: tempSum -= tempCard[1]; break; case 2: tempSum *= tempCard[1]; break; case 3: tempSum /= tempCard[1]; break; } switch (op2) { case 0: tempSum += tempCard[2]; break; case 1: tempSum -= tempCard[2]; break; case 2: tempSum *= tempCard[2]; break; case 3: tempSum /= tempCard[2]; break; } switch (op3) { case 0: tempSum += tempCard[3]; break; case 1: tempSum -= tempCard[3]; break; case 2: tempSum *= tempCard[3]; break; case 3: tempSum /= tempCard[3]; break; } if (tempSum == 24) { num[0] = tempCard[0]; num[1] = tempCard[1]; num[2] = tempCard[2]; num[3] = tempCard[3]; switch (op1) { case 0: sign[0] = '+'; break; case 1: sign[0] = '-'; break; case 2: sign[0] = '*'; break; case 3: sign[0] = '/'; break; } switch (op2) { case 0: sign[1] = '+'; break; case 1: sign[1] = '-'; break; case 2: sign[1] = '*'; break; case 3: sign[1] = '/'; break; } switch (op3) { case 0: sign[2] = '+'; break; case 1: sign[2] = '-'; break; case 2: sign[2] = '*'; break; case 3: sign[2] = '/'; break; } return true; } } } } } } } } return false; } int main() { char input[15]; while (fgets(input, sizeof(input), stdin) != NULL) { int len = strlen(input); if (len > 8) { printf("ERROR\n"); continue; } int card[4] = {0}; int nums = 0; for (int i = 0; i < len; i++) { if (input[i] >= '2' && input[i] <= '9') card[nums++] = input[i] - '0'; else if (input[i] == '1') { card[nums++] = 10; i++; } else if (input[i] == 'J') card[nums++] = 11; else if (input[i] == 'Q') card[nums++] = 12; else if (input[i] == 'K') card[nums++] = 13; else if (input[i] == 'A') card[nums++] = 1; } if (calculate(card)) { char output[4][2]; for(int i = 0; i < 4; i++) { if(num[i] >= 2 && num[i] <= 9) { output[i][0] = num[i] + '0'; output[i][1] = '\0'; } else if(num[i] == 10) { strcpy(output[i], "10"); } else if(num[i] == 11) { strcpy(output[i], "J"); } else if(num[i] == 12) { strcpy(output[i], "Q"); } else if(num[i] == 13) { strcpy(output[i], "K"); } else if(num[i] == 1) { strcpy(output[i], "A"); } } printf("%s%c%s%c%s%c%s\n", output[0], sign[0], output[1], sign[1], output[2], sign[2], output[3]); } else { printf("NONE\n"); } } return 0; }