当前位置:网站首页>C # input how many cards are there in each of the four colors.
C # input how many cards are there in each of the four colors.
2022-07-05 23:46:00 【laocooon】
namespace ConsoleCards
{
public enum Suit
{
Clubs,
Diamonds,
Hearts,
Spades
}
}
using System;
namespace ConsoleCards
{
public class Card
{
private Rank rank;
private Suit suit;
private bool faceUp;
public Rank Rank => rank;
public Suit Suit => suit;
public bool FaceUp => faceUp;
public Card(Rank rank, Suit suit)
{
this.rank = rank;
this.suit = suit;
faceUp = false;
}
public void FlipOver()
{
faceUp = !faceUp;
}
public void Print()
{
if (faceUp)
{
Console.WriteLine(string.Concat(rank, " of ", suit));
}
else
{
Console.WriteLine("Card is face down");
}
}
}
}
using System;
using System.Collections.Generic;
using ConsoleCards;
namespace ProgrammingAssignment3
{
/// <summary>
/// Programming Assignment 3
/// </summary>
class Program
{
// autograder support
static int testCaseNumber = 0;
static int nextCard = 0;
static Card[] testCaseCards = new Card[9];
static int numCards = 0;
/// <summary>
/// Programming Assignment 3
/// </summary>
/// <param name="args">command-line args</param>
static void Main(string[] args)
{
// IMPORTANT: Only add code in the section
// indicated below. The code I've provided
// makes your solution work with the
// automated grader on Coursera
string input = Console.ReadLine();
while (input[0] != 'q')
{
testCaseNumber = int.Parse(input);
numCards = GetNumCards();
InitializeTestCaseCards();
Card [] cards= testCaseCards;
nextCard = 0;
// Add your code between this comment
// and the comment below. You can of
// course add more space between the
// comments as needed
int[] arr = { 0, 0, 0, 0 };
while(nextCard < numCards)
arr[(int)GetCard().Suit]++;
Console.WriteLine("C"+arr[0]+ " D"+arr[1] + " H"+arr[2]+ " S"+arr[3]);
// Don't add or modify any code below
// this comment
input = Console.ReadLine();
}
}
/// <summary>
/// Gets a card
/// <return>a card</return>
/// </summary>
static Card GetCard()
{
nextCard++;
return testCaseCards[nextCard - 1];
}
/// <summary>
/// Gets how many cards will be in the hand for the
/// current test case number
/// <return>number of cards to add to hand</return>
/// </summary>
static int GetNumCards()
{
switch (testCaseNumber)
{
case 1:
case 2:
case 6:
return 5;
case 3:
return 2;
case 4:
return 7;
case 5:
return 0;
case 7:
return 1;
case 8:
case 10:
return 4;
case 9:
return 9;
default:
return 0;
}
}
/// <summary>
/// Initializes the set of cards returned by GetCard based
/// on the test case number
/// </summary>
static void InitializeTestCaseCards()
{
switch (testCaseNumber)
{
case 1:
testCaseCards[0] = new Card(Rank.Two, Suit.Clubs);
testCaseCards[1] = new Card(Rank.Three, Suit.Diamonds);
testCaseCards[2] = new Card(Rank.Four, Suit.Spades);
testCaseCards[3] = new Card(Rank.Ten, Suit.Spades);
testCaseCards[4] = new Card(Rank.Ace, Suit.Spades);
break;
case 2:
testCaseCards[0] = new Card(Rank.Two, Suit.Clubs);
testCaseCards[1] = new Card(Rank.Three, Suit.Clubs);
testCaseCards[2] = new Card(Rank.Four, Suit.Clubs);
testCaseCards[3] = new Card(Rank.Ten, Suit.Clubs);
testCaseCards[4] = new Card(Rank.Ace, Suit.Clubs);
break;
case 3:
testCaseCards[0] = new Card(Rank.Ten, Suit.Diamonds);
testCaseCards[1] = new Card(Rank.Ace, Suit.Diamonds);
break;
case 4:
testCaseCards[0] = new Card(Rank.Two, Suit.Hearts);
testCaseCards[1] = new Card(Rank.Three, Suit.Hearts);
testCaseCards[2] = new Card(Rank.Four, Suit.Hearts);
testCaseCards[3] = new Card(Rank.Five, Suit.Hearts);
testCaseCards[4] = new Card(Rank.Six, Suit.Hearts);
testCaseCards[5] = new Card(Rank.Seven, Suit.Hearts);
testCaseCards[6] = new Card(Rank.Eight, Suit.Hearts);
break;
case 6:
testCaseCards[0] = new Card(Rank.Ten, Suit.Clubs);
testCaseCards[1] = new Card(Rank.Jack, Suit.Clubs);
testCaseCards[2] = new Card(Rank.Queen, Suit.Clubs);
testCaseCards[3] = new Card(Rank.King, Suit.Clubs);
testCaseCards[4] = new Card(Rank.Ace, Suit.Clubs);
break;
case 7:
testCaseCards[0] = new Card(Rank.Queen, Suit.Hearts);
break;
case 8:
testCaseCards[0] = new Card(Rank.Jack, Suit.Clubs);
testCaseCards[1] = new Card(Rank.Jack, Suit.Diamonds);
testCaseCards[2] = new Card(Rank.Jack, Suit.Hearts);
testCaseCards[3] = new Card(Rank.Jack, Suit.Spades);
break;
case 9:
testCaseCards[0] = new Card(Rank.Two, Suit.Spades);
testCaseCards[1] = new Card(Rank.Three, Suit.Spades);
testCaseCards[2] = new Card(Rank.Four, Suit.Spades);
testCaseCards[3] = new Card(Rank.Five, Suit.Spades);
testCaseCards[4] = new Card(Rank.Six, Suit.Spades);
testCaseCards[5] = new Card(Rank.Seven, Suit.Spades);
testCaseCards[6] = new Card(Rank.Eight, Suit.Spades);
testCaseCards[7] = new Card(Rank.Nine, Suit.Spades);
testCaseCards[8] = new Card(Rank.Ten, Suit.Spades);
break;
case 10:
testCaseCards[0] = new Card(Rank.Two, Suit.Clubs);
testCaseCards[1] = new Card(Rank.Three, Suit.Diamonds);
testCaseCards[2] = new Card(Rank.Four, Suit.Hearts);
testCaseCards[3] = new Card(Rank.Five, Suit.Spades);
break;
default:
break;
}
}
}
}
边栏推荐
- 4点告诉你实时聊天与聊天机器人组合的优势
- How to insert data into MySQL database- How can I insert data into a MySQL database?
- Rasa 3.x 学习系列-Rasa X 社区版(免费版) 更改
- MySQL (2) -- simple query, conditional query
- Fiddler Everywhere 3.2.1 Crack
- 20220703 week race: number of people who know the secret - dynamic rules (problem solution)
- TVS管和ESD管的技術指標和選型指南-嘉立創推薦
- STM32__ 06 - single channel ADC
- poj 2762 Going from u to v or from v to u? (推断它是否是一个薄弱环节图)
- 424. The longest repeated character after replacement ●●
猜你喜欢
How to get all the values stored in localstorage
多普勒效应(多普勒频移)
Neural structured learning - Part 2: training with natural graphs
Redis高可用——主从复制、哨兵模式、集群
Online yaml to CSV tool
MySQL delete uniqueness constraint unique
Technical specifications and model selection guidelines for TVs tubes and ESD tubes - recommended by jialichuang
Biased sample variance, unbiased sample variance
20.移植Freetype字体库
There are 14 God note taking methods. Just choose one move to improve your learning and work efficiency by 100 times!
随机推荐
Redis高可用——主从复制、哨兵模式、集群
带外和带内的区别
UVA11294-Wedding(2-SAT)
做自媒体影视短视频剪辑号,在哪儿下载素材?
Tips for using pads router
LeetCode——Add Binary
Online yaml to CSV tool
Spire.PDF for NET 8.7.2
进击的技术er——自动化
How to design API return code (error code)?
[Yu Yue education] NC machining technology reference materials of Shaanxi University of science and technology
Data analysis - Thinking foreshadowing
424. The longest repeated character after replacement ●●
TS type declaration
ts类型声明declare
Latex multiple linebreaks
15 MySQL-存储过程与函数
Cwaitabletimer timer, used to create timer object access
VS2010编写动态链接库DLL和单元测试,转让DLL测试的正确性
98. 验证二叉搜索树 ●●