← 返回 rippling 的题目列表Camel Cards (Simplified Poker) — Hand Comparison with Extensible Hand Types (OOD)
类型:online_judge
Problem: Camel Cards (Simplified Poker) Hand Comparison (OOD)
Implement a simplified poker-like game called Camel Cards to determine which of two players has the stronger hand.
Rules
Two players, each has one hand.
Each hand consists of exactly 4 cards, represented as a string, e.g. "2332", "9998".
Card ranks are one of (high to low):
9, 8, 7, 6, 5, 4, 3, 2, 1
Hand Types (strongest to weakest)
Each hand belongs to exactly one of:
Four of a kind: all four cards the same (e.g. "9999")
Two pair: two of one rank + two of another (e.g. "2332")
Three of a kind: three of one rank + one different (e.g. "9998")
One pair: two of one rank + two distinct others (e.g. "5233")
High card: all cards distinct (e.g. "2345")
More hand types will be added in the future, so design for easy extensibility (OOD / good OOP practices).
Ordering Rules
Hands are ordered primarily by hand type (stronger type always wins).
If two hands have the same type:
Compare card-by-card from most recently dealt to first dealt (i.e., right to left in the string).
Do not sort the cards.
The first position where ranks differ determines the winner.
If all four positions match, it’s a tie.
Task
Implement:
evaluate(hand1: string, hand2: string) -> string
Return:
"HAND_1" if hand1 wins
"HAND_2" if hand2 wins
"TIE" if tied
Example
Input: hand1 = "2332", hand2 = "2442"
Both are Two pair
Compare from right to left: 2 vs 2 (tie), then 3 vs 4 → 4 wins
Output: "HAND_2"
Constraints/Notes
Hand length is always 4.
Cards are only from {1..9}.
Emphasize clean extensible object-oriented design (e.g., pluggable hand-type evaluators).
Example
Input
2332
2442
Output
HAND_2