#include <stdio.h>
#include <ctype.h>
int cardValue(char card) {
if (card >= '2' && card <= '9') {
return card - '0';
} else if (card == 'T' || card == 'K' || card == 'Q' || card == 'J') {
return 10;
} else if (card == 'A') {
return 11;
} else {
return -1; // Invalid card
}
}
int blackjackHandValue(char card1, char card2) {
int value1 = cardValue(card1);
int value2 = cardValue(card2);
if (value1 == -1 || value2 == -1) {
printf("*** Invalid card input\n");
return -1;
}
int total = value1 + value2;
// Adjust for the case of two aces
if (card1 == 'A' && card2 == 'A') {
total = 12;
}
return total;
}
int main() {
char card1, card2;
printf("Enter cards: ");
scanf(" %c %c", &card1, &card2);
// Convert to uppercase to handle lowercase input
card1 = toupper(card1);
card2 = toupper(card2);
int score = blackjackHandValue(card1, card2);
if (score != -1) {
printf("The score is %d\n", score);
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxjdHlwZS5oPgoKaW50IGNhcmRWYWx1ZShjaGFyIGNhcmQpIHsKICAgIGlmIChjYXJkID49ICcyJyAmJiBjYXJkIDw9ICc5JykgewogICAgICAgIHJldHVybiBjYXJkIC0gJzAnOwogICAgfSBlbHNlIGlmIChjYXJkID09ICdUJyB8fCBjYXJkID09ICdLJyB8fCBjYXJkID09ICdRJyB8fCBjYXJkID09ICdKJykgewogICAgICAgIHJldHVybiAxMDsKICAgIH0gZWxzZSBpZiAoY2FyZCA9PSAnQScpIHsKICAgICAgICByZXR1cm4gMTE7CiAgICB9IGVsc2UgewogICAgICAgIHJldHVybiAtMTsgLy8gSW52YWxpZCBjYXJkCiAgICB9Cn0KCmludCBibGFja2phY2tIYW5kVmFsdWUoY2hhciBjYXJkMSwgY2hhciBjYXJkMikgewogICAgaW50IHZhbHVlMSA9IGNhcmRWYWx1ZShjYXJkMSk7CiAgICBpbnQgdmFsdWUyID0gY2FyZFZhbHVlKGNhcmQyKTsKCiAgICBpZiAodmFsdWUxID09IC0xIHx8IHZhbHVlMiA9PSAtMSkgewogICAgICAgIHByaW50Zigi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