微软面试题 #2 —— 卡牌游戏模拟-微软面经 – Microsoft 面经 – VO辅助 – 代面试

57次阅读
没有评论

Design a simulation for a card game. This game is playable by 2 or more players
and consists of four phases performed in order: shuffle, deal, exchange, and score.

  • shuffle: randomize the order of a deck of 52 playing cards
  • deal: from the top of the deck, give each player 5 cards
  • exchange: each player may discard as many cards (face down) as they would like.
    After they have discarded their cards, draw from the top of the deck
    until the player has 5 cards in their hand.
  • score: determine which player has the highest numerical value of cards in their hand
    (face cards are worth 10 points each). If exactly one player has the highest
    combined value, then that player is declared the winner of the game.

Deck of cards:

  • 13 cards per suit: A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K
  • 4 suits: HEARTS, DIAMONDS, CLUBS, SPADES

思路

  1. 定义 Card / Deck / Player 类(OOP 加分)。
  2. 生成 52 张牌,并用随机数洗牌。
  3. 发牌给所有玩家。
  4. 玩家丢弃任意数量牌,再从牌堆顶部补齐。
  5. 把 J/Q/K/A 视为 10 分,算总点数。
  6. 找出唯一最高分的玩家。

整个任务考察:
✅ 程序设计能力
✅ 模拟类问题
✅ 面向对象设计
✅ 随机、数据结构、循环等基础

VOprep 团队长期陪同学员实战各类大厂 OA 与 VO,包括微软、Google、Amazon、Citadel、SIG 等,提供实时答案助攻、远程陪练与面试节奏提醒,帮助大家在关键时刻不卡壳。
如果你也在准备 Stripe 或类似工程向公司,可以了解一下我们的定制助攻方案——从编程面到系统设计,全程护航上岸。

正文完
 0