题目描述
Problem Description
A global hit word-guessing game now has a mathematical version! In this game, the computer secretly generates a hidden expression, such as \(90/5 \times 2 = 36\). However, the computer does not reveal the specific expression to you, but only the result of the expression (in the example, it's 36). Next, you need to guess the expression with the fewest attempts possible!
You can interact with the computer multiple times to make guesses. In each round of the game, you can tell the computer a string expression of length 6, consisting only of digits \(\texttt{0123456789}\) and arithmetic operations \(\texttt{+-*/}\). The expression does not contain negative numbers and digits do not have leading zeros, and the result of the expression must be the value given at the start of the game (in our example, it's 36). After receiving your guessed expression, the computer will provide feedback for each character in your expression:
- Green: The character appears in the hidden expression and is in the correct position.
- Yellow: The character appears in the hidden expression but is in the wrong position.
- Gray: The character does not appear in the hidden expression.
Here is an example of guessing the hidden expression in three attempts:

After guessing many times, you find the game a bit boring. Now you want to write a program to replace you and obtain the hidden expression within 12 guesses.
Input Format
This is an interactive problem, and the judge will simulate keyboard input and read the program's screen output. First, the judge program will input an integer \(n\) from the keyboard, representing the result of the hidden expression, then it will enter interactive mode and wait for your program to output a line (a guess for the hidden expression). After reading your output, the judge program will provide feedback via keyboard input. The following C++ code snippet can achieve interaction with the judge program (you need to complete other necessary parts):
cin >> n; // int n;
while (true) {
cout << guess(n) << endl; // Make a guess, note that a newline is required
cin >> res; // string res; Feedback from the computer
if (res == "AAAAAA") {
break; // Game over
}
}
During the interaction, the judge program will promptly provide feedback to your output:
- For incorrect expressions (e.g., extra spaces, invalid expressions, or wrong values), feedback will be six half-width minus signs (\(\texttt{"-"}\)).
- For correct-valued expressions, feedback will be six characters, where:
- \(\texttt{"A"}\) indicates the character appears in the expression and is in the correct position.
- \(\texttt{"B"}\) indicates the character appears in the expression but is in the wrong position.
- \(\texttt{"X"}\) indicates the character does not appear in the expression.
Note that the same digit may appear multiple times in the hidden expression. If a digit appears multiple times in your guessed expression, the judge program will prioritize \(\texttt{"A"}\) results, then give \(\texttt{"B"}\) results from left to right, and the remaining digits will get \(\texttt{"X"}\) results. Obtaining \(\texttt{"AAAAAA"}\) within 12 guesses and the program terminating normally is considered correct.
Arithmetic rules in this problem: multiplication and division first, then addition and subtraction, with the same priority calculated from left to right, and negative numbers are allowed during calculation. Division is rational division, not integer division, i.e., \(\texttt{2/5*10}\) equals 4, and division by zero is prohibited. The complete interaction process should be completed within 1 second; the judge program's running time is very short and can be ignored.
Output Format
See Input Format.
Sample Input and Output
Sample Input #1
36
XXXBXB
------
BAXBAX
AAAAAA
Sample Output #1
6+3*10
6+3*11
50-2*7
90/5*2
Sample Input #2
8
BXXXXX
XXXXBX
ABBABX
AAAAAA
Sample Output #2
10-4+2
7*6-34
3+15/3
35/5+1
Notes
The interaction process of Sample Group 1 corresponds to the interaction process in the problem diagram, but there is an illegal expression input in the middle.
For 50% of the data, the hidden expression contains at most two operators, and the operators are only addition and subtraction.
For 100% of the data, \(1 \leq n \leq 999,999\). It is guaranteed that there is at least one expression whose result equals \(n\).
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分