算24点纸牌游戏【破代码】

本文介绍了一种解决经典24点游戏的算法实现。通过全排列和符号循环检测的方法,该程序能够找出四张牌面值通过加减乘除运算达到24的所有可能组合。文章提供了详细的代码实现及样例输入输出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 1530: Interesting Card Game [有趣的纸牌游戏]


Time Limit: 2000 ms    Memory Limit: 32000 kB  
Judge type: Multi-cases Special Judge (Detailed Mode - 10 cases)
Total Submit : 340  (69 users)    Accepted Submit : 110  (55 users)    Page View : 2967 
Font Style: Aa Aa Aa

Whenever going to other places for contests, the ACM team of Nankai University always takes along a pack of cards to kill time on the train.

The rule of the card game is very simple. Before the game starts, the jokers are taken out from the cards. And then, 4 pieces of cards are taken out and shown each time. "A" stands for 1. "J" stands for 11. "Q" stands for 12. "K" stands for 13.Then, every player tries to join the four numbers with "+", "-", "*", "/", "(", ")" into an arithmetic expression which equals to 24. The winner is the one who figures out the correct arithmetic expression or confirms no solution for the four cards most quickly. Of course, each card must be used and could only be used once only.

Now, could you design a program to win the interesting card game more easily?

Input

Input contains several cases. The input is ended up with the end of file (EOF).

Each case contains only one line which includes only four integers, standing for the four cards taken out. The integers are between 1 and 13. (including 1 and 13) And the four integers will be separated from each other by a blank.

Output

For each case, please output two lines.

The first line for the i-th input case should be "Case i:", and the second line should be an arithmetic expression which satisfies the rule, and anyone is acceptable, if there are no less than one solution. If no solution exists, just output "No Solution!" in the second line of the case.

For an arithmetic expression, extra brackets are allowed. Take cards "1" , "2", "3" and "4" for example, the following arithmetic expressions are all accepted:

(1+2+3)*4

(((1+2)+3)*4)

1*2*3*4

Sample Input

1 2 3 4
1 1 1 1

Sample Output

Case 1:
(1+2+3)*4
Case 2:
No Solution!

 

 

代码看看吧: 我先全排列  然后符号循环检测  再前两个和后两个另外检测

写的很破 如果谁有好的写的  马上发我邮箱吧  谢谢~~~

helihui2@163.com  

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

helihui123

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值