当前位置:网站首页>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;
}
}
}
}
边栏推荐
- 20.移植Freetype字体库
- MySQL (2) -- simple query, conditional query
- Live tiktok shop 2022 latest gameplay card slot overseas live e-commerce new traffic
- AsyncSocket长连接棒包装问题解决
- The use of El cascader and the solution of error reporting
- Technical specifications and model selection guidelines for TVs tubes and ESD tubes - recommended by jialichuang
- MySQL delete uniqueness constraint unique
- SpreadJS 15.1 CN 与 SpreadJS 15.1 EN
- Spire Office 7.5.4 for NET
- poj 2762 Going from u to v or from v to u? (infer whether it is a weak link diagram)
猜你喜欢

Pyqt control part (I)

Comparison of parameters between TVs tube and zener diode

用列表初始化你的vector&&initializer_list简介

如何让同步/刷新的图标(el-icon-refresh)旋转起来

Tips for using pads router

STM32__ 06 - single channel ADC

My colleagues quietly told me that flying Book notification can still play like this

5. Logistic regression

Bao Yan notes II software engineering and calculation volume II (Chapter 13-16)

开关电源Buck电路CCM及DCM工作模式
随机推荐
Rasa 3. X learning series -rasa 3.2.1 new release
Cwaitabletimer timer, used to create timer object access
AsyncSocket长连接棒包装问题解决
Neural structured learning - Part 2: training with natural graphs
TVS管和ESD管的技术指标和选型指南-嘉立创推荐
How to improve eloquence
Spire Office 7.5.4 for NET
2022.6.20-6.26 AI行业周刊(第103期):新的小生命
20.移植Freetype字体库
Bao Yan notes II software engineering and calculation volume II (Chapter 13-16)
Code farmers to improve productivity
How to get all the values stored in localstorage
My colleagues quietly told me that flying Book notification can still play like this
Spire Office 7.5.4 for NET
In C#, why can't I modify the member of a value type instance in a foreach loop?
Fiddler Everywhere 3.2.1 Crack
ts类型声明declare
Introduction to JVM
How to rotate the synchronized / refreshed icon (EL icon refresh)
GFS分布式文件系统