当前位置:网站首页>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;
}
}
}
}
边栏推荐
- Switching power supply buck circuit CCM and DCM working mode
- 如何让同步/刷新的图标(el-icon-refresh)旋转起来
- Zero rhino technology joined hands with the intelligence Club: the "causal faction" forum was successfully held, and the "causal revolution" brought the next generation of trusted AI
- VS2010 writes DLL and unit test of dynamic link library, and transfers the correctness of DLL test
- How to insert data into MySQL database- How can I insert data into a MySQL database?
- orgchart. JS organization chart, presenting structural data in an elegant way
- PADS ROUTER 使用技巧小记
- The PostgreSQL column reference 'ID' is ambiguous - PostgreSQL column reference'id'is ambiguous
- 20220703 周赛:知道秘密的人数-动规(题解)
- UVA – 11637 Garbage Remembering Exam (组合+可能性)
猜你喜欢
Data analysis - Thinking foreshadowing
保研笔记一 软件工程与计算卷二(1-7章)
Zero rhino technology joined hands with the intelligence Club: the "causal faction" forum was successfully held, and the "causal revolution" brought the next generation of trusted AI
The use of El cascader and the solution of error reporting
开源crm客户关系统管理系统源码,免费分享
98. 验证二叉搜索树 ●●
GFS distributed file system
【经典控制理论】自控实验总结
Rasa 3. X learning series -rasa x Community Edition (Free Edition) changes
Neural structured learning 4 antagonistic learning for image classification
随机推荐
Creative mode 1 - single case mode
Go language introduction detailed tutorial (I): go language in the era
Comparison of parameters between TVs tube and zener diode
【经典控制理论】自控实验总结
15 MySQL stored procedures and functions
证明 poj 1014 模优化修剪,部分递归 有错误
Qcombox (rewrite) + qcompleter (auto completion, auto loading the drop-down options of qcombox, setting the background color)
Opencvsharp (C openCV) shape detection and recognition (with source code)
【SQL】各主流数据库sql拓展语言(T-SQL 、 PL/SQL、PL/PGSQL)
Do you regret becoming a programmer?
Spécifications techniques et lignes directrices pour la sélection des tubes TVS et ESD - Recommandation de jialichuang
带外和带内的区别
2022.6.20-6.26 AI行业周刊(第103期):新的小生命
asp. Net pop-up layer instance
[Yu Yue education] NC machining technology reference materials of Shaanxi University of science and technology
CIS benchmark tool Kube bench
CIS基准测试工具kube-bench使用
保研笔记二 软件工程与计算卷二(13-16章)
Zero rhino technology joined hands with the intelligence Club: the "causal faction" forum was successfully held, and the "causal revolution" brought the next generation of trusted AI
Cwaitabletimer timer, used to create timer object access