-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP462.cpp
99 lines (88 loc) · 1.7 KB
/
P462.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
typedef PC CARD; // Pair of chars.
int suitIdx(char suit) {
switch(suit) {
case 'S':
return 0;
case 'H':
return 1;
case 'D':
return 2;
default:
return 3;
}
}
int rule1(char c) {
switch(c) {
case 'A':
return 4;
case 'K':
return 3;
case 'Q':
return 2;
case 'J':
return 1;
default:
return 0;
}
}
int main() {
string s;
vector<char> hand[4]; // suit -> cards
bool stopped[4];
while(true) {
// Reset:
FORI(4) {
hand[i].clear();
stopped[i] = false;
}
int pts = 0;
int numStopped = 0;
FORI(13) {
if(!(cin >> s))
return 0;
hand[suitIdx(s[1])].push_back(s[0]);
pts += rule1(s[0]);
}
// Rules 2-4:
FORI(4) {
FORIT(vector<char>, hand[i]) {
char c = *it;
if(c == 'K' && hand[i].size() == 1)
--pts; // Rule 2
if(c == 'Q' && hand[i].size() <= 2)
--pts; // Rule 3
if(c == 'J' && hand[i].size() <= 3)
--pts; // Rule 4
// Find out if stopped:
if(!stopped[i] && (c == 'A' || (c == 'K' && hand[i].size() >= 2) || (c == 'Q' && hand[i].size() >= 3))) {
stopped[i] = true;
++numStopped;
}
}
}
if(pts >= 16 && numStopped == 4) {
cout << "BID NO-TRUMP" << endl;
continue;
}
// Rule 5 - 7:
FORI(4) {
if(hand[i].size() == 2)
++pts; // Rule 5
else if(hand[i].size() == 1)
pts+=2; // Rule 6
else if(hand[i].empty())
pts+=2; // Rule 7
}
if(pts < 14) {
cout << "PASS" << endl;
continue;
}
char suits[4] = {'S', 'H', 'D', 'C'};
int bestSuit = 0;
for(int i = 1; i < 4; ++i) {
if(hand[i].size() > hand[bestSuit].size())
bestSuit = i;
}
cout << "BID " << suits[bestSuit] << endl;
}
}