#AJ1601. AGRAM(初级)

AGRAM(初级)

Description

ACSL Agram is a card game for 2 players, using the cards from a 36-card pack. The cards are numbered from 1 to 9 and are in the suits Clubs, Diamonds, Hearts and Spades. The dealer deals five cards to each player. The opponent player leads any card, playing it face up in the middle of the playing area.

For this program the following strategy will be used to determine which card the dealer will play:

  1. The dealer must play a card of the same suit if he can.
  2. He plays the lowest card in that suit that is of a higher rank than the card the opponent played.
  3. If he does not have such a card (higher rank), he plays his lowest card in that suit.
  4. If no card can be played (dealer has no cards of the same suit), print NONE.

Input Format

There will be 5 lines of input. Each line will contain the opponent's lead card and the 5 cards held by the dealer. All cards will be represented by two characters in value-suit order (e.g., 5, D).

Output Format

For each input line print the card the dealer must play according to the strategy listed above. If no card can be played print NONE.

Explanation

Example 1: Lead 5, D. Dealer has 2, D, 6, H, 9, D, 9, S, 6, H. Suits match: 2, D and 9, D. 9, D is greater than 5, D. 2, D is smaller. Play the lowest card higher than 5, D: 9, D.

Example 3: Lead 3, D. Dealer has 2, D, 1, D (and others). Suits match: 2, D, 1, D. Neither is greater than 3, D. Play the lowest card of the suit: 1, D.

Example 4: Lead 9, S. Dealer has 8, H, 7, C, 7, D, 9, H, 3, H. No Spades in dealer's hand. Output: NONE.

5, D, 2, D, 6, H, 9, D, 9, S, 6, H
9, D
4, C, 1, C, 6, C, 7, H, 5, S, 4, D
6, C
3, D, 4, H, 5, C, 6, S, 2, D, 1, D
1, D
9, S, 8, H, 7, C, 7, D, 9, H, 3, H
NONE
1, C, 1, D, 9, H, 8, S, 9, S, 7, C
7, C