-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathChickenOracle.cpp
61 lines (51 loc) · 1.19 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
53
54
55
56
57
58
59
60
61
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <numeric>
using namespace std;
class ChickenOracle {
public:
bool check(int n, int eggCount, int lie, int lier) {
bool ret = false;
int ec = n - lie;
int left = max(lier - (n - ec), 0);
int right = min(ec, lier);
int i, tmp;
for (i=left; i<=right; i++) {
tmp = ec - i + (lier - i);
if (tmp == eggCount) {
ret = true;
break;
}
}
return ret;
}
string theTruth(int n, int eggCount, int lieCount, int liarCount) {
string ret;
bool isEgg = check(n, eggCount, lieCount, liarCount);
bool isChicken = check(n, n - eggCount, lieCount, liarCount);
if (isEgg && isChicken)
ret = "Ambiguous";
else if (isEgg)
ret = "The egg";
else if (isChicken)
ret = "The chicken";
else
ret = "The oracle is a lie";
return ret;
}
};
// Powered by FileEdit
// Powered by TZTester 1.01 [25-Feb-2003]
// Powered by CodeProcessor