Task DescriptionDiscussion (0)
Task :: Questionmark
You are given an expression, containing integer numbers between 0 and 999, simple mathematical operators (+, -, *, /), parentheses, and question marks (?). You can substitute a questionmark with any of the four possible operators (+, -, *, /).
For a given expression, you have to find out whether you can substitute the questionmarks with mathematical operators such that the evaluted expression equals to some given integer N.
The expressions have the following restrictions:
1. The expressions contain no more than 500 symbols.
2. The constants in the expressions have no sign, i.e. there are no negative numbers in the expressions;
3. .The maximum number of question marks in the expressions is 20.
The calculation should be performed using the following rules:
1. The operators * and / are of higher priority than the operators + and -. Parentheses may change the priorities as usually;
2. The operators +, -, *, and / are left associative, meaning that they group from left to right. If a, b and c are numbers: a*b*c = (a*b)*c, a/b/c = (a/b)/c, a/b*c = (a/b)*c, a+b+c = (a+b)+c, a-b+c = (a-b)+c, etc.
3. When dividing two integers, you should ignore the decimal fraction, for example consider the following equations: 2/5=0, 9/5=1, 100/6=16.
For a given expression, you have to find out whether you can substitute the questionmarks with mathematical operators such that the evaluted expression equals to some given integer N.
The expressions have the following restrictions:
1. The expressions contain no more than 500 symbols.
2. The constants in the expressions have no sign, i.e. there are no negative numbers in the expressions;
3. .The maximum number of question marks in the expressions is 20.
The calculation should be performed using the following rules:
1. The operators * and / are of higher priority than the operators + and -. Parentheses may change the priorities as usually;
2. The operators +, -, *, and / are left associative, meaning that they group from left to right. If a, b and c are numbers: a*b*c = (a*b)*c, a/b/c = (a/b)/c, a/b*c = (a/b)*c, a+b+c = (a+b)+c, a-b+c = (a-b)+c, etc.
3. When dividing two integers, you should ignore the decimal fraction, for example consider the following equations: 2/5=0, 9/5=1, 100/6=16.
INPUT:
The first line contains the given expression. The second line contains the number N
The first line contains the given expression. The second line contains the number N
OUTPUT:
Write yes or no
Write yes or no
Input:
1?2*3+4-14
0
Output:0
no
Input:
1?((2*(3*4))+(5+6))
35
Output:35
yes
Submit Solution
Home
Training
Competitions
Forum
FAQ