Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int a, b, c, d, e;
- bool able;
- void execute();
- bool calculate(int i1, int i2, int i3, int i4);
- int main()
- {
- int loop;
- cin >> loop;
- while(loop--)
- {
- cin >> a;
- cin >> b;
- cin >> c;
- cin >> d;
- cin >> e;
- able = false;
- execute();
- if(!able)
- cout << "NO" << endl;
- else
- cout << "YES" << endl;
- }
- return 0;
- }
- void execute()
- {
- //1 = +; 2 = -; 3 = *;
- for(int i1 = 1; i1 <= 3; i1++)
- {
- for(int i2 = 1; i2 <= 3; i2++)
- {
- for(int i3 = 1; i3 <= 3; i3++)
- {
- for(int i4 = 1; i4 <= 3; i4++)
- {
- if(calculate(i1, i2, i3, i4))
- {
- able = true;
- return;
- }
- }
- }
- }
- }
- }
- bool calculate(int i1, int i2, int i3, int i4)
- {
- int result = a;
- //i1
- if(i1 == 1)
- result += b;
- else if(i1 == 2)
- result -= b;
- else if(i1 == 3)
- result *= b;
- //i2
- if(i2 == 1)
- result += c;
- else if(i2 == 2)
- result -= c;
- else if(i2 == 3)
- result *= c;
- //i3
- if(i3 == 1)
- result += d;
- else if(i3 == 2)
- result -= d;
- else if(i3 == 3)
- result *= d;
- //i4
- if(i4 == 1)
- result += e;
- else if(i4 == 2)
- result -= e;
- else if(i4 == 3)
- result *= e;
- if(result == 23)
- return true;
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement