Codechef Code Crunch 2013 Black Jack
Black JackProblem code: MRIU14 |
Problem description.
Blackjack is a very well known gambling card game played against a
dealer in a casino. In this card game, each player is trying to beat
the dealer, by obtaining a sum of card values not more than 21
which is greater than the sum of dealer card values. Player is initially
given 2 cards, but he could choose to HIT (ask for 3rd card) or STAND
(no more cards). If he chooses to hit for 3rd card and total score
crosses 21 he get busted (loses irrespective of the total score of
dealer cards). Face cards (Jacks, Queens and Kings) are worth 10
points. Aces are worth 1 or 11, whichever is preferable. Other cards
are represented by their number.
Here, you have to implement a conservative player strategy of
playing blackjack. This conservative player does not want to get
busted and hit only when its safe to do so. He follows following
strategy:
HIT if (score<=11) or (an ACE is held)
STAND otherwise.
Write a program to implement the above strategy given the initial 2
cards of the player.
Input
First line T, will have a single integer having number of test cases followed by T lines of input.
Second Line will have two space seperated inputs (value of first and second card).
and so on..
Output
For each test case, output a single line containing the result.
Constraints
1) Color of the card does not affects the score of
the card.
2) If the value of card is not valid then return INVALID.
3) Don't consider the card with value 10(print INVALID).
4) Input for Face cards must be capital
letters('A','Q','J','K') else return INVALID.
Example
Input 3 J 5 4 3 A F Output: STAND HIT INVALID
Explanation
1. Here the value of J (JACK) is
10. so the sum of card values is 15, so he
chooses to stand.
2. Here the sum of values of card
4 and 3 is 7. It is less than 11, so it makes
sense for him to draw another card.
3. Here F is an invalid card name.
1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include <map> 3 #include <queue> 4 #include <vector> 5 #include <string> 6 #include <cstdio> 7 #include <cstring> 8 #include <iostream> 9 #include <algorithm> 10 using namespace std; 11 #define maxn 10005 12 #define mod 1000000007 13 #define ll long long 14 #define INF 0x7fffffff 15 int n, m; 16 char s1[maxn]; 17 char s2[maxn]; 18 int main(){ 19 int cas = 1; 20 int t; 21 scanf("%d", &t); 22 while (t--){ 23 scanf("%s%s", s1, s2); 24 n = 0; m = 0; 25 if (s1[0] >'1'&&s1[0] <='9')n += s1[0] - '0'; 26 if (s2[0] >'1'&&s2[0] <='9')m += s2[0] - '0'; 27 if (s1[0] == 'J')n += 10; 28 if (s2[0] == 'J')m += 10; 29 if (s1[0] == 'Q')n += 10; 30 if (s2[0] == 'Q')m += 10; 31 if (s1[0] == 'K')n += 10; 32 if (s2[0] == 'K')m += 10; 33 if (s1[0]=='A')n += 1; 34 if (s2[0]=='A')m += 1; 35 if (n == 0 || m==0){printf("INVALID\n"); continue;} 36 if (n + m == 11 && s1[0] == 'A' || s2[0] == 'A'){ printf("STAND\n"); continue; } 37 if (n + m <= 11||s1[0]=='A'||s2[0]=='A')printf("HIT\n"); 38 else printf("STAND\n"); 39 } 40 /*while (~scanf("%s", s)){ 41 42 }*/ 43 return 0; 44 }
浙公网安备 33010602011771号