Gennady and a Card Game Gennady和纸牌游戏

Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called “Mau-Mau”.

To play Mau-Mau, you need a pack of 52 cards. Each card has a suit (Diamonds — D, Clubs — C, Spades — S, or Hearts — H), and a rank (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A).

At the start of the game, there is one card on the table and you have five cards in your hand. You can play a card from your hand if and only if it has the same rank or the same suit as the card on the table.

In order to check if you’d be a good playing partner, Gennady has prepared a task for you. Given the card on the table and five cards in your hand, check if you can play at least one card.
根纳迪在乡下开了一家小旅馆,过着平静的生活。他喜欢散步,看日落,和住在他酒店的游客打牌。他最喜欢的游戏叫“毛毛”。
要玩毛毛,你需要一包52张牌。每张牌都有一套套装(钻石-D,梅花-C,黑桃-S或红心-H)和一个等级(2,3,4,5,6,7,8,9,T,J,Q,K或a)。
游戏开始时,桌上有一张牌,你手里有五张牌。当且仅当你手上的牌与桌上的牌具有相同的等级或相同的套装时,你才可以玩这张牌。
为了检查你是否是一个好搭档,根纳迪为你准备了一个任务。给桌上的牌和你手上的五张牌,检查你是否至少能玩一张牌。

Input
The first line of the input contains one string which describes the card on the table. The second line contains five strings which describe the cards in your hand.

Each string is two characters long. The first character denotes the rank and belongs to the set {2,3,4,5,6,7,8,9,T,J,Q,K,A}. The second character denotes the suit and belongs to the set {D,C,S,H}.

All the cards in the input are different.
输入的第一行包含一个描述表上卡片的字符串。第二行包含五个字符串来描述你手中的牌。
每个字符串有两个字符长。第一个字符表示秩,属于集合{2,3,4,5,6,7,8,9,T,J,Q,K,A}。第二个字符表示西装,属于集合{D,C,S,H}。
输入中的所有卡片都不同。

Output
If it is possible to play a card from your hand, print one word “YES”. Otherwise, print “NO”.

You can print each letter in any case (upper or lower).
如果可以从你手上打出一张牌,请打印一个字“是”。否则,打印“否”。
你可以在任何情况下打印每个字母(大写或小写)。

Examples
Input
AS
2H 4C TH JH AD
Output
YES
Input
2H
3D 4C AC KD AS
Output
NO
Input
4D
AS AC AD AH 5H
Output
YES

Note
In the first example, there is an Ace of Spades (AS) on the table. You can play an Ace of Diamonds (AD) because both of them are Aces.

In the second example, you cannot play any card.

In the third example, you can play an Ace of Diamonds (AD) because it has the same suit as a Four of Diamonds (4D), which lies on the table.
在第一个例子中,桌子上有一张黑桃王牌。你可以玩钻石王牌(AD),因为他们都是王牌。
在第二个例子中,你不能玩任何牌。
在第三个例子中,你可以玩一个钻石王牌(AD),因为它和放在桌子上的四颗钻石(4D)有相同的套装。

题解:
第一行和第二行的字符作比较,至少一个相同即可出牌。

#include<iostream>
#include<string>
using namespace std;
int main()
{
	string a;
	cin>>a;
	string b[5],s;
	for(int i=0;i<5;++i){
		cin>>b[i];
		s+=b[i];
	}    //b吃掉空格后得到s
	int flag=0;
	for(int i=0;i<11;++i){
		if(s[i]==a[0]||s[i]==a[1]) {
			flag=1;
		}   //遍历s,与a作比较,若有相同的,说明有牌可打
	}
	if(flag==1) cout<<"YES";
	else cout<<"NO";
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值