【find】#82 A. Card Game

A. Card Game
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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).

Sample test(s)
input
H
QH 9S
output
YES
input
S
8D 6D
output
YES
input
C
7H AS
output
NO


两张牌比大小的游戏。

第一个字母是牌面点数,第二个是花色(Spade黑桃、Heart红桃、Diamond方片、Clover梅花(其实是四叶草啦))

先给出的那个字母是王牌花色,如果两张牌一个是王牌另一个不是,那么王牌花色获胜,如果都是或者都不是比点数大小。

这里我用了find函数 find(begin,end,key)可以返回找到的值在数组内的指针,指针之间可以相减获得距离。

#include <cstdio>
#include <string>
#include <vector>
#include <cstring> 
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
// http://codeforces.com/contest/106
// Card Game
char tramp[9]={'6','7','8','9','T','J','Q','K','A'};

int main()
{
	string trp;	cin>>trp;
	string a,b;	cin>>a>>b;
	if(a[1]==trp[0] && b[1]!=trp[0]) cout<<"YES";
	else if(a[1]!=trp[0] && b[1]==trp[0]) cout<<"NO";
	else 
	{
		int dist=find(tramp,tramp+9,a[0])-find(tramp,tramp+9,b[0]);
		if(dist>0) cout<<"YES";
		else cout<<"NO";
	}
	return 0;
} 




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

糖果天王

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

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

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

打赏作者

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

抵扣说明:

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

余额充值