52张牌随意发
uses
SysUtils,Classes;
type
CardType=array[0..3] of string;
const CardNums=12;
type
RCardrecord=record
CardInfo: string;
end;
PCard=^RCardrecord;
var
slist: TList;
i,j: Integer;
iSub,iSpare: Integer;
sCardType,sCardNum: string;
aCard: PCard;
iRandom,iCount: Integer;
tCardInfo: string;
aCardType: CardType;
begin
try
{ TODO -oUser -cConsole Main : Insert code here }
aCardType[0]:='S';
aCardType[1]:='H';
aCardType[2]:='D';
aCardType[3]:='C';
slist := TList.Create;
for i := 1 to 52 do
begin
iSub:=i div 14;
iSpare:=i mod 14;
sCardType := aCardType[iSub];
sCardNum := IntToHex(iSpare,1);
New(aCard);
aCard.CardInfo := sCardType+sCardNum;
slist.Add(aCard);
end;
Randomize;
for j := 0 to 3 do
begin
tCardInfo := '';
for i := 1 to CardNums do
begin
iRandom:=Random(slist.Count);
aCard:=slist.Items[iRandom];
tCardInfo := tCardInfo + ' ' + aCard^.CardInfo;
slist.Delete(iRandom);
Dispose(aCard);
end;
Writeln(tCardInfo);
end;
iCount:=slist.Count;
for i := iCount-1 downto 0 do
begin
aCard:=slist.Items[i];
slist.Delete(i);
Dispose(aCard);
end;
slist.Free;
Readln(i);
except
on E:Exception do
Writeln(E.Classname, ': ', E.Message);
end;
end.