2818. Card Game(字符串比较)

2818. Card Game 

There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly − you can find them later yourselves if you want.

To play durak you need a pack of 36 cards. Each card has a suit ("S", "H", "D" and "C") and a rank (in the increasing order "6", "7", "8", "9", "T", "J", "Q", "K" and "A"). At the beginning of the game one suit is arbitrarily chosen as trump.

The players move like that: one player puts one or several of his cards on the table and the other one should beat each of them with his cards.

A card beats another one if both cards have similar suits and the first card has a higher rank then the second one. Besides, a trump card can beat any non-trump card whatever the cards’ ranks are. In all other cases you can not beat the second card with the first one.

You are given the trump suit and two different cards. Determine whether the first one beats the second one or not.

Input

The first line contains the tramp suit. It is "S", "H", "D" or "C".

The second line contains the description of the two different cards. Each card is described by one word consisting of two symbols. The first symbol stands for the rank ("6", "7", "8", "9", "T", "J", "Q", "K" and "A"), and the second one stands for the suit ("S", "H", "D" and "C").

Output

Print "YES" (without the quotes) if the first cards beats the second one. Otherwise, print "NO" (also without the quotes).

Examples

Input

H
QH 9S

Output

YES

 input

S
8D 6D

Output 

YES

input 

C

7H AS

 Output 

NO  

已经ac的代码。

这个题主要是审题清楚知道,具体比较规则,第二张牌为什么比第一张牌大。还有输出的yes和no都是大写。

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
    string trip;
    cin >> trip;  //输入王牌
    string a1,a2;  //输入两张牌
	int i1=0;
	int i2=0;
    cin >> a1>> a2;
    char a[9] = {'6','7','8','9','T','J','Q','K','A'};  //牌中的花色大小
    if(a1[1]==trip[0]&&a2[1] != trip[0])   //判断两张牌中是否有王牌
        cout << "YES";
    else if(a1[1]!=trip[0]&&a2[1] == trip[0])
    {
       cout <<"NO";
    }
    else
    {
		if(a1[1]==a2[1]) //在两张牌花色相同的情况下,比较数点的大小
		{
			for(int i=0;i<=9;i++)
			{
				if(a[i]==a1[0])
				{
					i1=i;
				}
				else if(a[i]==a2[0])
				{
					i2=i;
				}
			}
			
			if(i1>i2)
			{
				cout << "YES";
			}
			else
			{
				cout << "NO";
			}
		}
		else  //花色不同的情况下第一张牌不=不能打败第二张
		{
			cout<<"NO";
		}
    }
    return 0;
}

 

import pygame import time from collections import deque class CardRecorder: def __init__(self): """初始化记录系统""" self.current_game_records = [] # 当前游戏记录 self.current_round_cards = [] # 当前轮次记录 self.player_roles = { 0: "landlord", 1: "farmer_left", 2: "farmer_right" } self.reset_game() def reset_game(self): """重置游戏记录[^3]""" self.current_game_records = [] self.current_round_cards = [] print("游戏记录已重置") def record_card(self, player_id, card): """记录玩家出牌[^2] :param player_id: 玩家ID (0=地主,1=左农民,2=右农民) :param card: 出的牌 (字符串表示,如"3♦") """ timestamp = time.strftime("%H:%M:%S") record = { "order": len(self.current_round_cards) + 1, "role": self.player_roles[player_id], "card": card, "time": timestamp } self.current_round_cards.append(record) print(f"记录: {record}") def finish_one_round(self): """完成一轮出牌[^2]""" if self.current_round_cards: self.current_game_records.append(self.current_round_cards.copy()) self.current_round_cards.clear() print("本轮出牌结束,记录已保存") def display_records(self): """显示当前游戏记录""" print("\n=== 当前游戏出牌记录 ===") for round_idx, round_cards in enumerate(self.current_game_records, 1): print(f"\n第{round_idx}轮:") for play in round_cards: print(f"玩家[{play['role']}] 出牌: {play['card']} ({play['time']})") if self.current_round_cards: print("\n=== 当前轮次出牌 ===") for play in self.current_round_cards: print(f"玩家[{play['role']}] 出牌: {play['card']} ({play['time']})") def end_game(self): """游戏结束处理[^3]""" self.display_records() self.reset_game() # 使用@property保护内部状态[^1] class GameState: def __init__(self): self._is_playing = False @property def is_playing(self): return self._is_playing @is_playing.setter def is_playing(self, value): if not isinstance(value, bool): raise ValueError("游戏状态必须为布尔值") self._is_playing = value # 示例使用 if __name__ == "__main__": recorder = CardRecorder() game_state = GameState() game_state.is_ 解释代码
最新发布
06-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值