-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathChickenOracle.cpp
52 lines (46 loc) · 1.06 KB
/
ChickenOracle.cpp
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<iostream>
#include<cstdio>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<list>
#include<deque>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<utility>
#include<sstream>
#include<cstring>
using namespace std;
class ChickenOracle {
public:
string theTruth(int n, int egg, int lie, int liar) {
int chicken = n-egg;
bool e, c;
e = c = false;
int a = egg-lie;
int b = chicken+lie;
if (a == liar)
c = true;
else if (b == liar)
e = true;
a = egg+lie;
b = chicken-lie;
if (a == liar)
c = true;
else if (b == liar)
e = true;
if (e && c)
return "Ambiguous";
else if (e)
return "The egg";
else if (c)
return "The chicken";
else
return "The oracle is a lie";
}
};