參考答案:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CSD04
{
class Program
{
static void Main(string[] args)
{
int[] card = new int[5];
Random r = new Random();
string type=null, num;
for (int i = 0; i < card.Count(); i++)
{
bool check = false;
do
{
card[i] = r.Next(1, 52);
if (i == 0)
check = true;
else
{
for (int j = 0; j < i; j++)
{
if (card[j] == card[i])
{
check = false;
break;
}
else
check = true;
}
}
}while(check==false);
if (card[i] >= 1 && card[i] <= 13)
type = "Clubs";
else if (card[i] >= 14 && card[i] <= 26)
type = "Diamonds";
else if (card[i] >= 27 && card[i] <= 39)
type = "Hearts";
else if (card[i] >= 40 && card[i] <= 52)
type = "Spades";
num = (card[i]%13).ToString();
switch (num)
{
case "11":
num = "J";
break;
case "12":
num = "Q";
break;
case "0":
num = "K";
break;
default:
break;
}
Console.WriteLine("No.{0}, {1} {2}",i+1,type,num);
}Console.Read();
}
}
}
執行結果:
留言列表