编程介的小学生 2019-06-05 13:58 采纳率: 20.5%
浏览 174

写程序判断三张扑克牌比赛的获胜者,用C语言技术编写出的程序的代码编写程序如何判断的呢

Problem Description
The inhabitants of a small Caribbean island in the region known as Bermuda's Triangle love to spend their warm summer nights playing cards. As a tribute to the region where they live, all of their card games have some connection to triangles. One of the most popular games in the island is known as Triples, and has very simple rules.

The game is played between two players, with a set of standard playing cards. Cards are distinguished only by their values, from 1 (Ace) to 13 (King). The cards are shuffled and placed as a pile in the center of the table, face down. This pile is called the stock. The two players take turns at playing. At each turn, a player
●draws the top card from the stock, adding it to her/his hand; and
●decides whether she/he wants to "drop some triples"

Dropping a triple consists of choosing three cards (a triple) from the hand and placing them on the table, face up. The dropped triples stay on the table until the end of the game.

Only some sets of three cards form a valid triple. There are two types of valid triples:
●Perfect triples are made of three cards whose values represent the length of sides of an equilateral triangle;
●Common triples are made by three cards whose values represent the length of sides of any other (not equilateral) triangle.

The figure below shows examples of perfect triples (a), common triples (b), and invalid triples(c).

Only valid triples can be dropped, but a player may drop any number of triples at a given turn. In particular, since players know the number of cards in the stock at every turn, a player may decide to drop all triples in her/his last turn. Some players, however, normally drop some triples during the game, to maintain as few cards in their hands as possible.

The game finishes when the stock is empty. The winner is the player that dropped the largest number of perfect triples. If both players dropped the same number of perfect triples, the winner is the player that dropped the largest number of common triples. If both players dropped the same number of perfect triples and the same number of common triples, the result is a tie.

Given the description of the cards in the stock, write a program that determines the winner of a game of Triples, considering both players play as best as possible.

Input
The input contains several test cases. The first line of a test case contains one integer N representing the number of cards in the stock (6 <= N <= 104). The next line contains N integers Xi, separated by single spaces, representing the cards in the stock (1 <= Xi <= 13, for 1 <= i <= N). The cards are given in the order they are drawn by the players: the first card in the input (X1) is the first card drawn, the second card in the input (X2) is the second card drawn, and so on. Several cards with the same value may be present in the stock, and not necessarily all card values are present in the stock. The end of input is indicated by N = 0.

Output
For each test case your program must output a single line, containing '1'
if the first player to play wins the game, '2' if the second player wins, or '0' if there is a tie.

Sample Input
7
5 6 5 6 5 6 8
12
13 13 13 13 13 13 1 3 2 9 3 9
12
1 2 1 2 1 2 3 1 4 2 5 3
0

Sample Output
0
2
1

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集
    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)