/*
原文地址:梦忻屋博客http://www.mxwu.cn/?p=310
作者 : wanglichao
*/
因为代码中含有一些和wordpress冲突的内容,所以为了保全整个代码,博主不得不将代码存到这边来,大家将就看着。
type card=record d,h:longint;end;
var st:string;i,j,k,kk,min,p,des:longint;bo:boolean;t:card;
hand:array[1..5]of card;a:array[1..10]of card;
function what:longint;
function sf:boolean;
begin
for i:=2 to 5 do
if(hand[i].h<>hand[i-1].h)then
exit(false);
exit(true);
end;
function foak:boolean;
begin
for i:=1 to 2 do
if(hand[i].d=hand[i+3].d)then
exit(true);
exit(false);
end;
function fh:boolean;
begin
if(hand[1].d=hand[3].d)and(hand[4].d=hand[5].d)then exit(true);
if(hand[1].d=hand[2].d)and(hand[3].d=hand[5].d)then exit(true);
exit(false);
end;
function f:boolean;
begin
for i:=2 to 5 do
if(hand[i].h<>hand[i-1].h)then exit(false);
exit(true);
end;
function s:boolean;
begin
for i:=3 to 5 do
if not(hand[i].d=hand[i-1].d+1)then exit(false);
if(hand[2].d=hand[1].d+1)or(hand[5].d=13)and(hand[1].d=1)then
exit(true);
exit(false);
end;
function toak:boolean;
begin
for i:=3 to 5 do
if (hand[i-2].d=hand[i].d)and(hand[i].d=hand[i-1].d) then exit(true);
exit(false);
end;
function tp:boolean;
begin
bo:=false;
for i:=2 to 5 do
if hand[i].d=hand[i-1].d then
begin
if bo then exit(true);
bo:=true;
end;
exit(false);
end;
function op:boolean;
begin
for i:=2 to 5 do
if hand[i].d=hand[i-1].d then
exit(true);
exit(false);
end;
begin
if sf and s then exit(0);
if foak then exit(1);
if fh then exit(2);
if f then exit(3);
if s then exit(4);
if toak then exit(5);
if tp then exit(6);
if op then exit(7);
exit(8);
end;
begin
while not eof do
begin
readln(st);st:=st+' ';
write('Hand: ',copy(st,1,15),'Deck: ',copy(st,16,30));
for i:=1 to 10 do
begin
case st[1] of
'T':a[i].d:=10;
'J':a[i].d:=11;
'Q':a[i].d:=12;
'K':a[i].d:=13;
'A':a[i].d:=1;
else a[i].d:=ord(st[1])-48;
end;
case st[2] of
'H':a[i].h:=1;
'C':a[i].h:=2;
'D':a[i].h:=3;
'S':a[i].h:=4;
end;
delete(st,1,3);
end;
min:=8;
for kk:=0 to 31 do
begin
for j:=1 to 5 do
hand[j]:=a[j];
p:=kk;
j:=16;
k:=1;des:=5;
while(j>0)do
begin
if(p>=j)then
begin
p:=p-j;
des:=des+1;
hand[k]:=a[des];
end;
j:=j div 2;
k:=k+1;
end;
for i:=1 to 4 do
for j:=i+1 to 5 do
if(hand[i].d>hand[j].d)then
begin t:=hand[i];hand[i]:=hand[j];hand[j]:=t;end;
i:=what;
if i min:=i;
end;
write('Best hand: ');
case min of
0:writeln('straight-flush');
1:writeln('four-of-a-kind');
2:writeln('full-house');
3:writeln('flush');
4:writeln('straight');
5:writeln('three-of-a-kind');
6:writeln('two-pairs');
7:writeln('one-pair');
8:writeln('highest-card');
end;
end;
end.
原文地址:梦忻屋博客http://www.mxwu.cn/?p=310
作者 : wanglichao
*/
因为代码中含有一些和wordpress冲突的内容,所以为了保全整个代码,博主不得不将代码存到这边来,大家将就看着。
type card=record d,h:longint;end;
var st:string;i,j,k,kk,min,p,des:longint;bo:boolean;t:card;
hand:array[1..5]of card;a:array[1..10]of card;
function what:longint;
function sf:boolean;
begin
for i:=2 to 5 do
if(hand[i].h<>hand[i-1].h)then
exit(false);
exit(true);
end;
function foak:boolean;
begin
for i:=1 to 2 do
if(hand[i].d=hand[i+3].d)then
exit(true);
exit(false);
end;
function fh:boolean;
begin
if(hand[1].d=hand[3].d)and(hand[4].d=hand[5].d)then exit(true);
if(hand[1].d=hand[2].d)and(hand[3].d=hand[5].d)then exit(true);
exit(false);
end;
function f:boolean;
begin
for i:=2 to 5 do
if(hand[i].h<>hand[i-1].h)then exit(false);
exit(true);
end;
function s:boolean;
begin
for i:=3 to 5 do
if not(hand[i].d=hand[i-1].d+1)then exit(false);
if(hand[2].d=hand[1].d+1)or(hand[5].d=13)and(hand[1].d=1)then
exit(true);
exit(false);
end;
function toak:boolean;
begin
for i:=3 to 5 do
if (hand[i-2].d=hand[i].d)and(hand[i].d=hand[i-1].d) then exit(true);
exit(false);
end;
function tp:boolean;
begin
bo:=false;
for i:=2 to 5 do
if hand[i].d=hand[i-1].d then
begin
if bo then exit(true);
bo:=true;
end;
exit(false);
end;
function op:boolean;
begin
for i:=2 to 5 do
if hand[i].d=hand[i-1].d then
exit(true);
exit(false);
end;
begin
if sf and s then exit(0);
if foak then exit(1);
if fh then exit(2);
if f then exit(3);
if s then exit(4);
if toak then exit(5);
if tp then exit(6);
if op then exit(7);
exit(8);
end;
begin
while not eof do
begin
readln(st);st:=st+' ';
write('Hand: ',copy(st,1,15),'Deck: ',copy(st,16,30));
for i:=1 to 10 do
begin
case st[1] of
'T':a[i].d:=10;
'J':a[i].d:=11;
'Q':a[i].d:=12;
'K':a[i].d:=13;
'A':a[i].d:=1;
else a[i].d:=ord(st[1])-48;
end;
case st[2] of
'H':a[i].h:=1;
'C':a[i].h:=2;
'D':a[i].h:=3;
'S':a[i].h:=4;
end;
delete(st,1,3);
end;
min:=8;
for kk:=0 to 31 do
begin
for j:=1 to 5 do
hand[j]:=a[j];
p:=kk;
j:=16;
k:=1;des:=5;
while(j>0)do
begin
if(p>=j)then
begin
p:=p-j;
des:=des+1;
hand[k]:=a[des];
end;
j:=j div 2;
k:=k+1;
end;
for i:=1 to 4 do
for j:=i+1 to 5 do
if(hand[i].d>hand[j].d)then
begin t:=hand[i];hand[i]:=hand[j];hand[j]:=t;end;
i:=what;
if i min:=i;
end;
write('Best hand: ');
case min of
0:writeln('straight-flush');
1:writeln('four-of-a-kind');
2:writeln('full-house');
3:writeln('flush');
4:writeln('straight');
5:writeln('three-of-a-kind');
6:writeln('two-pairs');
7:writeln('one-pair');
8:writeln('highest-card');
end;
end;
end.