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

2个回答

0
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
[游戏报错问题解决方案] 关于GTA5 unrecoverable fault报错问题的解决方案
问题描述:可正常进入GTA5进行游戏,但是在接受任务或者复活时,弹出unrecoverable fault错误。 解决办法:删除文档里面的R星全部文件夹(最好备份到其他目录一份),检查游戏完整性,开启游戏加速器,进入游戏,即可正常运行,初步判断是在读取或者储存存档时由于网络原因导致的错误。建议选择云存档。 ...
生命游戏(c语言)
Conway——the game of life,特别发行的精装版,以此来纪念一年来学习编程的蛋疼时光!
android 最新31个游戏合集 game 31个_2.rar
android 最新31个游戏合集 game 31.rar 第二个包
3D游戏引擎编程_part5of31
3D Game Engine Programming 3D游戏引擎编程 pdf 一共31个包,下齐后解压.
android 最新31个游戏合集 game 31个_3.rar
第三个包,android 游戏 game G3 G2之前已经描述了
3D游戏引擎编程part25of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part31of31
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游戏引擎编程part21of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part4of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part28of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part1of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part8of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压
3D游戏引擎编程part13of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part11of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part24of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part26of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part10of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part27of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part9of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part19of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part2of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part20of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part29of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part12of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part16of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part17of31
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游戏引擎编程part15of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part7of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程_part3of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part22of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
3D游戏引擎编程part30of31
3D Game Engine Programming<br>3D游戏引擎编程<br>pdf<br>一共31个包,下齐后解压.
game game game game game
很好玩的小游戏,适合上班时间消遣!有空下了玩玩吧!
Unity面试题 易错题
(单选题)以下关于MonoBehavior.OnGUI()的描述错误的是()  A.如果调用MonoBehaviour没有被启用,则OnGUI函数不会被调用  B.用于绘制和处理GUIevents  C.每帧可能会被绘制多次,每次对应于一个GUI event  D.每帧被调用一次 正确答案:D 解析: 此函数用于渲染和处理GUI事件时被调用,且每帧会按情况被调用多次。所以选择D。
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.
the game crashed的可能解决方案
打开游戏,或者一些类似游戏的软件时报错: 优先参考:https://tieba.baidu.com/p/5227459178?pv=1 如果按照上面的方案解决不了问题,你可以尝试切换显卡。 有一些国产辣鸡 软件不支持独立显卡,将该程序指定为使用集成显卡即可。 (没有外国月亮比较圆的意思,流入我们视线的外国软件,都是经过筛选的) ...