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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值