1097A Gennady and a Card Game

谁借莪1个温暖的怀抱¢ 2022-03-30 09:08 248阅读 0赞

A. Gennady and a Card Game

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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

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}{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}{D,C,S,H}.

All the cards in the input are different.

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

Copy

  1. AS
  2. 2H 4C TH JH AD

output

Copy

  1. YES

input

Copy

  1. 2H
  2. 3D 4C AC KD AS

output

Copy

  1. NO

input

Copy

  1. 4D
  2. AS AC AD AH 5H

output

Copy

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

题意:桌子上有一张牌,你手上有五张牌,能否打出一张牌,能打的条件是你手上的牌和桌子上的大小一样或者花色一样,最终目的是判断你手上的牌是否有一张和桌子上牌的其中一个字母是否一样。

题解:就是判断手上的牌是否有一张牌和桌子上的牌的字母其中一个一样。

c++:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. string s,a;
  6. cin>>s;
  7. for(int i=0; i<5; i++)
  8. {
  9. cin>>a;
  10. if(s[0]==a[0]||s[1]==a[1])
  11. return puts("YES"),0;
  12. }
  13. return puts("NO"),0;
  14. }

python:

  1. s=input()
  2. a=input()
  3. if s[0] in a or s[-1] in a:
  4. print("YES")
  5. else:print("NO")

发表评论

表情:
评论列表 (有 0 条评论,248人围观)

还没有评论,来说两句吧...

相关阅读