-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD.cpp
More file actions
34 lines (23 loc) · 1.06 KB
/
D.cpp
File metadata and controls
34 lines (23 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*One day, Ali Baba had an easy puzzle that he couldn't solve. The puzzle consisted of 4
numbers and his task was to check whether he could get the fourth number using arithmetic operators (+,−,×)
between the other three numbers; so that each operator is used only once.
a□b□c=d
Can you solve this tricky puzzle for him?
Input
Only one line containing four numbers a, b, cand d(−109≤a,b,c≤109),(−1018≤d≤1018).
Output
Print "YES" (without quotes) if you get the fourth number using arithmetic operators, otherwise, print "NO" (without quotes).*/
#include <iostream>
using namespace std;
int main() {
long long a,b,c,d;
cin>>a>>b>>c>>d;
if (a+b - c == d) { cout << "YES"; return 0; }
if (a+b * c == d) { cout << "YES"; return 0; }
if (a - b + c == d) { cout << "YES"; return 0; }
if (a - b * c == d) { cout << "YES"; return 0; }
if (a * b + c == d) { cout << "YES"; return 0; }
if (a * b - c == d) { cout << "YES"; return 0; }
else{ cout << "NO";}
return 0;
}