#include using namespace std; int main() { int num1[7] = {0, 1, 2, 5, 6, 8, 9}; //价牌包含的数字 int num2[7] = {0, 1, 2, 5, 9, 8, 6}; //价牌翻转对应的数字 int profit1[1111][2]; //利润1 int profit2[1111][2]; //利润2 int before_reverse; //颠倒前 int after_reverse; //颠倒后 int i = 0; int j = 0; for (int a = 1; a < 7; a++) //从1开始,第一位数字不可以是0 { for (int b = 0; b < 7; b++) { for (int c = 0; c < 7; c++) { for (int d = 0; d < 7; d++) { before_reverse = num1[a] * 1000 + num1[b] * 100 + num1[c] * 10 + num1[d]; after_reverse = num2[d] * 1000 + num2[c] * 100 + num2[b] * 10 + num2[a]; //因为是颠倒之后所以第一位可以是0 if (after_reverse - before_reverse > -300 && after_reverse - before_reverse < -200) //在200-300范围内,我们以正数为准 { profit1[i][0] = before_reverse; profit1[i][1] = after_reverse - before_reverse; i++; } else if (after_reverse - before_reverse > 800 && after_reverse - before_reverse < 900) //在800-900范围内 { profit1[j][0] = before_reverse; profit2[j][1] = after_reverse - before_reverse; j++; } } } } } int answer = 0; for (int a = 0; a < i; a++) { for (int b = 0; b < j; b++) { if (profit1[a][1] + profit2[b][1] == 558) { answer = profit1[a][0]; } } } cout << answer << endl; return 0; }