A. Cards

传送门

A. Cards

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

When Serezha was three years old, he was given a set of cards with letters for his birthday. They were arranged into words in the way which formed the boy’s mother favorite number in binary notation. Serezha started playing with them immediately and shuffled them because he wasn’t yet able to read. His father decided to rearrange them. Help him restore the original number, on condition that it was the maximum possible one.

Input
The first line contains a single integer n
(1⩽n⩽105) — the length of the string. The second line contains a string consisting of English lowercase letters: ‘z’, ‘e’, ‘r’, ‘o’ and ‘n’.It is guaranteed that it is possible to rearrange the letters in such a way that they form a sequence of words, each being either “zero” which corresponds to the digit 0 or “one” which corresponds to the digit 1

Output
Print the maximum possible number in binary notation. Print binary digits separated by a space. The leading zeroes are allowed.

Examples
Input
4
ezor
Output
0

Input
10
nznooeeoer
Output
1 1 0

Note
In the first example, the correct initial ordering is “zero”.
In the second example, the correct initial ordering is “oneonezero”.

题意:输入一串字符,字符由“o,n,e,z,r"组成,判断可输出的最大数字。

思路:因为输入符合“one"与”zero“的组成,所以“n”与"z"可以判断输出1还是0,只需扫描整个字符串,先判断扫到“n"时输出1,扫到”z”时输出0,这样就满足输出的数字是最大的。

AC代码

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
int main()
{
	int n, i;
	scanf("%d", &n);
	char a[n];
	scanf("%s", a);
	for (i = 0; i < n; i++)
	{
		if (a[i] == 'n')
		{
			printf("1 ");
		}
	}
	for (i = 0; i < n; i++)
	{
		if (a[i] == 'z')
		{
			printf("0 ");
		}
	}
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Sure, here is an implementation of the Pontoon game in Java: ``` import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class PontoonGame { private static final int MAX_SCORE = 21; private static final int MAX_NUM_CARDS = 5; private static final int DEALER_STAND_THRESHOLD = 16; private static final int CARD_VALUE_ACE = 11; private static final int CARD_VALUE_FACE = 10; private static final String[] SUITS = new String[] { "Hearts", "Diamonds", "Spades", "Clubs" }; private static final String[] RANKS = new String[] { "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace" }; private List<Card> deck; private List<Card> playerHand; private List<Card> dealerHand; public PontoonGame() { deck = new ArrayList<>(); playerHand = new ArrayList<>(); dealerHand = new ArrayList<>(); // Initialize deck for (String suit : SUITS) { for (String rank : RANKS) { deck.add(new Card(rank, suit)); } } } public void play() { Scanner scanner = new Scanner(System.in); System.out.println("Welcome to Pontoon! Would you like to play? (y/n)"); String input = scanner.nextLine(); if (!input.equalsIgnoreCase("y")) { return; } // Shuffle deck and deal cards Collections.shuffle(deck); playerHand.add(dealCard()); dealerHand.add(dealCard()); playerHand.add(dealCard()); dealerHand.add(dealCard()); // Show initial hands System.out.println("Your hand: " + playerHand); System.out.println("Dealer's hand: " + dealerHand.get(0) + ", [hidden]"); // Player's turn while (true) { System.out.println("Would you like to hit or stand? (h/s)"); input = scanner.nextLine(); if (input.equalsIgnoreCase("h")) { playerHand.add(dealCard()); System.out.println("Your hand: " + playerHand); if (getHandValue(playerHand) > MAX_SCORE) { System.out.println("Bust! You lose."); return; } } else if (input.equalsIgnoreCase("s")) { break; } else { System.out.println("Invalid input. Please enter 'h' or 's'."); } } // Dealer's turn while (getHandValue(dealerHand) < DEALER_STAND_THRESHOLD && getHandValue(playerHand) <= MAX_SCORE) { dealerHand.add(dealCard()); } System.out.println("Dealer's hand: " + dealerHand); // Determine winner int playerScore = getHandValue(playerHand); int dealerScore = getHandValue(dealerHand); if (playerScore > MAX_SCORE) { System.out.println("Bust! You lose."); } else if (dealerScore > MAX_SCORE) { System.out.println("Dealer busts! You win."); } else if (playerScore == dealerScore) { System.out.println("It's a tie!"); } else if (playerScore == MAX_SCORE || dealerScore > MAX_SCORE || playerScore > dealerScore) { System.out.println("You win!"); } else { System.out.println("Dealer wins!"); } } private Card dealCard() { if (deck.isEmpty()) { throw new IllegalStateException("Deck is empty."); } return deck.remove(0); } private int getHandValue(List<Card> hand) { int value = 0; int numAces = 0; for (Card card : hand) { if (card.getRank().equals("Ace")) { numAces++; } else if (card.getRank().equals("Jack") || card.getRank().equals("Queen") || card.getRank().equals("King")) { value += CARD_VALUE_FACE; } else { value += Integer.parseInt(card.getRank()); } } for (int i = 0; i < numAces; i++) { if (value + CARD_VALUE_ACE > MAX_SCORE) { value += 1; } else { value += CARD_VALUE_ACE; } } return value; } private static class Card { private final String rank; private final String suit; public Card(String rank, String suit) { this.rank = rank; this.suit = suit; } public String getRank() { return rank; } public String getSuit() { return suit; } @Override public String toString() { return rank + " of " + suit; } } public static void main(String[] args) { PontoonGame game = new PontoonGame(); game.play(); } } ``` This implementation uses object-oriented programming principles to model the game as a `PontoonGame` class that contains methods for playing the game. The game logic is implemented in the `play()` method, which prompts the user for input, deals cards, and determines the winner. The `Card` class is a nested class that represents a playing card with a rank and a suit.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

稚皓君

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

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

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

打赏作者

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

抵扣说明:

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

余额充值