fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <map>
  4. #include <string>
  5. #define SSTART 0
  6. #define HSTART 13
  7. #define DSTART 26
  8. #define CSTART 39
  9. using namespace std;
  10.  
  11.  
  12. int deck[52];
  13. map<char, int> pos;
  14.  
  15. void init() {
  16. for (int i = 0; i < 52; ++i)
  17. deck[i] = 0;
  18.  
  19. pos['S'] = SSTART;
  20. pos['H'] = HSTART;
  21. pos['D'] = DSTART;
  22. pos['C'] = CSTART;
  23. pos['2'] = 0;
  24. pos['3'] = 1;
  25. pos['4'] = 2;
  26. pos['5'] = 3;
  27. pos['6'] = 4;
  28. pos['7'] = 5;
  29. pos['8'] = 6;
  30. pos['9'] = 7;
  31. pos['T'] = 8;
  32. pos['J'] = 9;
  33. pos['Q'] = 10;
  34. pos['K'] = 11;
  35. pos['A'] = 12;
  36. }
  37.  
  38. void map_card(char rank, char suit) {
  39. int index = pos[suit] + pos[rank];
  40. deck[index] = 1;
  41. }
  42.  
  43. int rule_one() {
  44. int points = 0;
  45. points += (deck[pos['D'] + pos['A']]*4);
  46. points += (deck[pos['C'] + pos['A']]*4);
  47. points += (deck[pos['H'] + pos['A']]*4);
  48. points += (deck[pos['S'] + pos['A']]*4);
  49.  
  50. points += (deck[pos['D'] + pos['K']]*3);
  51. points += (deck[pos['C'] + pos['K']]*3);
  52. points += (deck[pos['H'] + pos['K']]*3);
  53. points += (deck[pos['S'] + pos['K']]*3);
  54.  
  55. points += (deck[pos['D'] + pos['Q']]*2);
  56. points += (deck[pos['C'] + pos['Q']]*2);
  57. points += (deck[pos['H'] + pos['Q']]*2);
  58. points += (deck[pos['S'] + pos['Q']]*2);
  59.  
  60. points += (deck[pos['D'] + pos['J']]);
  61. points += (deck[pos['C'] + pos['J']]);
  62. points += (deck[pos['H'] + pos['J']]);
  63. points += (deck[pos['S'] + pos['J']]);
  64.  
  65. return points;
  66. }
  67.  
  68. int helper_two(int start, int end, int king)
  69. {
  70. int points = 0;
  71. int length = 0;
  72. for (int i = start; i < end; ++i)
  73. if (deck[i] == 1)
  74. ++length;
  75. if (length == 1 && deck[king] == 1)
  76. points--;
  77. return points;
  78. }
  79.  
  80.  
  81. int rule_two() {
  82. int points = 0;
  83. int dking = pos['D'] + pos['K'];
  84. int cking = pos['C'] + pos['K'];
  85. int hking = pos['H'] + pos['K'];
  86. int sking = pos['S'] + pos['K'];
  87.  
  88. points += helper_two(SSTART,HSTART,sking);
  89. points += helper_two(HSTART,DSTART,hking);
  90. points += helper_two(DSTART,CSTART,dking);
  91. points += helper_two(CSTART,52,cking);
  92.  
  93. return points;
  94. }
  95.  
  96. int helper_three(int start, int end, int queen) {
  97. int points = 0;
  98. int length = 0;
  99.  
  100. for (int i = start; i < end; ++i)
  101. if (deck[i] == 1)
  102. length++;
  103. if (length <= 2 && deck[queen] == 1)
  104. points--;
  105. return points;
  106. }
  107.  
  108. int rule_three() {
  109. int points = 0;
  110. int dking = pos['D'] + pos['Q'];
  111. int cking = pos['C'] + pos['Q'];
  112. int hking = pos['H'] + pos['Q'];
  113. int sking = pos['S'] + pos['Q'];
  114.  
  115. points += helper_three(SSTART,HSTART,sking);
  116. points += helper_three(HSTART,DSTART,hking);
  117. points += helper_three(DSTART,CSTART,dking);
  118. points += helper_three(CSTART,52,cking);
  119.  
  120. return points;
  121. }
  122.  
  123. int helper_four(int start, int end, int jack) {
  124. int points = 0;
  125. int length = 0;
  126.  
  127. for (int i = start; i < end; ++i)
  128. if (deck[i] == 1)
  129. length++;
  130. if (length <= 3 && deck[jack] == 1)
  131. points--;
  132. return points;
  133. }
  134.  
  135. int rule_four() {
  136. int points = 0;
  137. int dking = pos['D'] + pos['J'];
  138. int cking = pos['C'] + pos['J'];
  139. int hking = pos['H'] + pos['J'];
  140. int sking = pos['S'] + pos['J'];
  141.  
  142. points += helper_four(SSTART,HSTART,sking);
  143. points += helper_four(HSTART,DSTART,hking);
  144. points += helper_four(DSTART,CSTART,dking);
  145. points += helper_four(CSTART,52,cking);
  146.  
  147. return points;
  148. }
  149.  
  150. int helper_five(int start, int end) {
  151. int points = 0;
  152. int length = 0;
  153.  
  154. for (int i = start; i < end; ++i)
  155. if (deck[i] == 1)
  156. length++;
  157. if (length == 2)
  158. points++;
  159. return points;
  160. }
  161.  
  162. int rule_five() {
  163. int points = 0;
  164.  
  165. points += helper_five(SSTART,HSTART);
  166. points += helper_five(HSTART,DSTART);
  167. points += helper_five(DSTART,CSTART);
  168. points += helper_five(CSTART,52);
  169.  
  170. return points;
  171. }
  172.  
  173. int helper_six(int start, int end) {
  174. int points = 0;
  175. int length = 0;
  176.  
  177. for (int i = start; i < end; ++i)
  178. if (deck[i] == 1)
  179. length++;
  180. if (length == 1)
  181. points+=2;
  182. return points;
  183. }
  184.  
  185. int rule_six() {
  186. int points = 0;
  187.  
  188. points += helper_six(SSTART,HSTART);
  189. points += helper_six(HSTART,DSTART);
  190. points += helper_six(DSTART,CSTART);
  191. points += helper_six(CSTART,52);
  192.  
  193. return points;
  194. }
  195.  
  196. int helper_seven(int start, int end) {
  197. int points = 0;
  198. int length = 0;
  199.  
  200. for (int i = start; i < end; ++i)
  201. if (deck[i] == 1)
  202. length++;
  203. if (length == 0)
  204. points+=2;
  205. return points;
  206. }
  207.  
  208. int rule_seven() {
  209. int points = 0;
  210.  
  211. points += helper_seven(SSTART,HSTART);
  212. points += helper_seven(HSTART,DSTART);
  213. points += helper_seven(DSTART,CSTART);
  214. points += helper_seven(CSTART,52);
  215.  
  216. return points;
  217. }
  218.  
  219. int rule(int n) {
  220. switch (n) {
  221. case 1:
  222. return rule_one();
  223. case 2:
  224. return rule_two();
  225. case 3:
  226. return rule_three();
  227. case 4:
  228. return rule_four();
  229. case 5:
  230. return rule_five();
  231. case 6:
  232. return rule_six();
  233. case 7:
  234. return rule_seven();
  235. default:
  236. return 0;
  237. }
  238. }
  239.  
  240. int compute_points() {
  241. int points = 0;
  242. for (int i = 0; i < 7; ++i)
  243. points += rule(i+1);
  244.  
  245. return points;
  246. }
  247.  
  248. int no_trump() {
  249. int points = 0;
  250. for (int i = 0; i < 4; ++i)
  251. points += rule(i+1);
  252.  
  253. return points;
  254. }
  255.  
  256. bool stopped_condition1(int start) {
  257. return deck[start + pos['A']];
  258. }
  259.  
  260. bool stopped_condition2(int start, int end) {
  261. bool king = deck[start + pos['K']];
  262. int length = 0;
  263. for (int i = start; i < end; ++i)
  264. if (deck[i])
  265. length++;
  266. bool result = (king && (length > 1));
  267. return result;
  268. }
  269.  
  270. bool stopped_condition3(int start, int end) {
  271.  
  272. bool queen = deck[start + pos['Q']];
  273. int length = 0;
  274. for (int i = start; i < end; ++i)
  275. if (deck[i])
  276. length++;
  277. bool result = (queen && (length > 2));
  278. }
  279.  
  280. bool all_stopped() {
  281. bool c1 = stopped_condition1(SSTART);
  282. bool c2 = stopped_condition2(SSTART,HSTART);
  283. bool c3 = stopped_condition3(SSTART,HSTART);
  284. bool c_1 = c1||c2||c3;
  285. if (c_1 == false)
  286. return false;
  287.  
  288. c1 = stopped_condition1(HSTART);
  289. c2 = stopped_condition2(HSTART,DSTART);
  290. c3 = stopped_condition3(HSTART,DSTART);
  291. bool c_2 = c1||c2||c3;
  292. if (c_2 == false)
  293. return false;
  294.  
  295. c1 = stopped_condition1(DSTART);
  296. c2 = stopped_condition2(DSTART,CSTART);
  297. c3 = stopped_condition3(DSTART,CSTART);
  298. bool c_3 = c1||c2||c3;
  299. if (c_3 == false)
  300. return false;
  301.  
  302. c1 = stopped_condition1(CSTART);
  303. c2 = stopped_condition2(CSTART,52);
  304. c3 = stopped_condition3(CSTART,52);
  305. bool c_4 = c1||c2||c3;
  306. if (c_4 == false)
  307. return false;
  308.  
  309. return c_1 && c_2 && c_3 && c_4;
  310. // shdc
  311. }
  312.  
  313. int suit_length(int start, int end) {
  314. int length = 0;
  315. for (int i = start; i < end; ++i)
  316. if (deck[i] == 1)
  317. ++length;
  318. return length;
  319. }
  320.  
  321. char best_suit() {
  322. char suit = 'S';
  323. int count = suit_length(SSTART,HSTART);
  324.  
  325. int temp = suit_length(HSTART,DSTART);
  326. if (count < temp) {
  327. suit = 'H';
  328. count = temp;
  329. }
  330.  
  331. temp = suit_length(DSTART,CSTART);
  332. if (count < temp) {
  333. count = temp;
  334. suit = 'D';
  335. }
  336.  
  337. temp = suit_length(CSTART,52);
  338. if(count < temp) {
  339. count = temp;
  340. suit = 'C';
  341. }
  342.  
  343. return suit;
  344. }
  345.  
  346. int main() {
  347. char r,s;
  348.  
  349. while (cin >> r) {
  350. init();
  351. cin >> s;
  352. map_card(r,s);
  353. for (int i = 0; i < 12; ++i) {
  354. cin >> r; cin >> s;
  355. map_card(r,s);
  356. }
  357. int trump_points = no_trump();
  358. bool stopped = all_stopped();
  359. int points = compute_points();
  360. if (trump_points >= 16 && stopped)
  361. cout << "BID NO-TRUMP" << endl;
  362. else if (points >= 14) {
  363. char suit = best_suit();
  364. cout << "BID " << suit << endl;
  365. }
  366. else
  367. cout << "PASS" << endl;
  368. }
  369.  
  370. return 0;
  371. }
  372.  
Success #stdin #stdout 0s 3480KB
stdin
AH QS 3S 7C 3C KC 8H AD AS 4D 5S 6S 3H
3S 2D JS AH 7C JH KH 4C TH TS AS TD 4D
JD KC 7C QD 3D 8C 5D 2S AS QC JH 2C KD
stdout
BID NO-TRUMP
BID S
BID D