#include 是什么?
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <stdlib.h>
using namespace std;
int get_card(int poker[52],int *pokerNum)
{
unsigned int seed;
struct timeval now;
int card,i;
gettimeofday(&now, NULL);
seed = now.tv_sec ^ now.tv_usec;
i=rand_r(&seed)%*pokerNum;
card=poker[i];
poker[i]=poker[*pokerNum-1];
*pokerNum=*pokerNum-1;
return card;
}
int main()
{
int pokerNum=52,i;
int my_card1,my_card2,my_card3,total1,total2;
int poker[]={2,3,4,5,6,7,8,9,10,10,10,10,11,2,3,4,5,6,7,8,9,10,10,10,10,11,2,3,4,5,6,7,8,9,10,10,10,10,11,2,3,4,5,6,7,8,9,10,10,10,10,11};
my_card1=get_card(poker,&pokerNum);
my_card2=get_card(poker,&pokerNum);
total1=my_card1+my_card2;
printf("Player draws %d and %d,total %d\r\n",my_card1,my_card2,total1);
if(total1>21)
printf("Dealer wins.\r\n");
else
{
my_card1=get_card(poker,&pokerNum);
my_card2=get_card(poker,&pokerNum);
total2=my_card1+my_card2;
printf("Dealer draws %d and %d,total %d\r\n",my_card1,my_card2,total2);
if(total2>21)
printf("Player wins.\r\n");
else
{
while(total2<17)
{
my_card3=get_card(poker,&pokerNum);
total2=total2+my_card3;
printf("Dealer draws %d,total %d\r\n",my_card3,total2);
}
if(total2>21)
printf("Player wins.\r\n");
else if(total2>total1)
printf("Dealer wins.\r\n");
else if(total2<total1)
printf("Player wins.\r\n");
else
{
total1=0;
total2=0;
while(total1==total2)
{
total1=get_card(poker,&pokerNum);
printf("Player draws %d\r\n",total1);
total2=get_card(poker,&pokerNum);
printf("Dealer draws %d\r\n",total2);
}
if(total1>total2)
printf("Player wins.\r\n");
else
printf("Dealer wins.\r\n");
}
}
}
return 0;
}
要把他改为一个C++ 程序,#include <sys/time.h> 如果是在C++ 应该替换成什么呢?