The Game of 31

The game of 31 was a favorite of con artists who rode the railroads in days of yore. The game is played with a deck of 24 cards: four labeled each of 1, 2, 3, 4, 5, 6. The cards in the deck are visible to both players, who alternately withdraw one card from the deck and place it on a pile. The object of the game is to be the last player to lay a card such that the sum of the cards in the pile does not exceed 31. Your task is to determine the eventual winner of a partially played game, assuming each player plays the remainder of the game using a perfect stratefy.
For example, in the following game player B wins:

Player A plays 3
Player B plays 5
Player A plays 6
Player B plays 6
Player A plays 5
Player B plays 6

Input

The input will consist of several lines; each line consists of a sequence of zero or more digits representing a partially completed game. The first digit is player A's move; the second player B's move; and so on. You are to complete the game using a perfect strategy for both players and to determine who wins.

Output

For each game, print a line consisting of the input, followed by a space, followed by A or B to indicate the eventual winner of the game.

Sample Input

356656
35665
3566
111126666
552525

Sample Output

356656 B
35665 B
3566 A
111126666 A
552525 A

0

1个回答

0
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
The Game of 31
The game of 31 was a favorite of con artists who rode the railroads in days of yore. The game is played with a deck of 24 cards: four labeled each of 1, 2, 3, 4, 5, 6. The cards in the deck are visible to both players, who alternately withdraw one card from the deck and place it on a pile. The object of the game is to be the last player to lay a card such that the sum of the cards in the pile does not exceed 31. Your task is to determine the eventual winner of a partially played game, assuming each player plays the remainder of the game using a perfect stratefy.nFor example, in the following game player B wins:nnPlayer A plays 3nPlayer B plays 5nPlayer A plays 6nPlayer B plays 6nPlayer A plays 5nPlayer B plays 6nnnInputnnThe input will consist of several lines; each line consists of a sequence of zero or more digits representing a partially completed game. The first digit is player A's move; the second player B's move; and so on. You are to complete the game using a perfect strategy for both players and to determine who wins.nnnOutputnnFor each game, print a line consisting of the input, followed by a space, followed by A or B to indicate the eventual winner of the game.nnnSample Inputnn356656n35665n3566n111126666n552525nnnSample Outputnn356656 Bn35665 Bn3566 An111126666 An552525 An
生命游戏(c语言)
Conway——the game of life,特别发行的精装版,以此来纪念一年来学习编程的蛋疼时光!
android 最新31个游戏合集 game 31个_2.rar
android 最新31个游戏合集 game 31.rar 第二个包
android 最新31个游戏合集 game 31个_3.rar
第三个包,android 游戏 game G3 G2之前已经描述了
3D游戏引擎编程_part5of31
3D Game Engine Programming 3D游戏引擎编程 pdf 一共31个包,下齐后解压.
game game game game game
很好玩的小游戏,适合上班时间消遣!有空下了玩玩吧!
Game Engine Architecture 3rd Edition
游戏引擎开发第三版高清版 New to the Third Edition This third edition offers the same comprehensive coverage of game engine architecture provided by previous editions, along with updated coverage of: computer and CPU hardware and memory caches, compiler optimizations, C++ language standardization, the IEEE-754 floating-point representation, 2D user interfaces, plus an entirely new chapter on hardware parallelism and concurrent programming.
Game AI Pro 3 Collected Wisdom of Game AI Professionals 无水印pdf
Game AI Pro 3 Collected Wisdom of Game AI Professionals 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
3D游戏引擎编程part10of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part25of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part24of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part31of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part3of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part19of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part6of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part14of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part20of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part17of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part8of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压
3D游戏引擎编程part28of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part9of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
facebook instant game 发布指南-最佳实践
小游戏最佳实践构建小游戏时,要求使用 HTML5 语言。下面是关于开发小游戏的一系列最佳实践:加载时间与性能   初始加载时间不应超过 5 秒:小游戏必须能够“即时”加载,如果初始加载时间太长,玩家将趋向于流失。捆绑包的总大小最多可为 200 MB,但在初始加载期间,我们仅加载您的index.html明确要求的文件。因此,请确保在初始加载期间仅加载关键素材,用于开启首次会话,并延迟其他素材的加载,...
3D游戏引擎编程part29of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part11of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part22of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part15of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part7of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part30of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
Game For Windows Live
用以解决某些游戏(如GTA4)缺少xlive.dll的问题,彻底解决此问题需要安装Game For Windows Live。
3D游戏引擎编程_part4of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part26of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part12of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part27of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part1of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part16of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part18of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part23of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part2of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part21of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part13of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
文章热词 机器学习 机器学习课程 机器学习教程 深度学习视频教程 深度学习学习
相关热词 c# game c++jump game c++ game of rows 31岁学习人工智能 python教程+chm