睡觉前之散分贴




内容不能为空
程序代码:/*
A与B各有一个硬币,并且同时出示自己的硬币。如果出示的两个硬币为正正(两个正面),则B给A 3元;如果出现反反,则B给A 1元;如果出现正反(反正),则
A给B 2元。请问这个游戏是公平的吗?
*/
#include <iostream>
#include <iomanip>
#include <stdlib.h>
using namespace std;
void main(void)
{
unsigned int Number = 500;
unsigned int Count;
int Money_A = 0;
int Money_B = 0;
int Card_A;
int Card_B;
int Win_A = 0;
int Win_B = 0;
cout << setw(5) << "No." << " | ";
cout << "Game" << " | ";
cout << setw(5) << "A" << " | ";
cout << setw(5) << "B";
cout << endl;
srand((unsigned)time(NULL));
for (Count = 1; Count <= Number; Count++)
{
cout << setw(5) << Count << " | ";
Card_A = rand() % 2;
Card_B = 0;
//Card_B = rand() % 2;
cout << " " << Card_A << " " << Card_B << " | ";
if ((Card_A == 1) && (Card_B == 1))
{
Money_A += 3;
Money_B -= 3;
}
if ((Card_A == 0) && (Card_B == 0))
{
Money_A += 1;
Money_B -= 1;
}
if (Card_A != Card_B)
{
Money_A -= 2;
Money_B += 2;
}
cout << setw(5) << Money_A << " | ";
cout << setw(5) << Money_B << endl;
if (Money_A > 0)
{
Win_A++;
}
if (Money_B > 0)
{
Win_B++;
}
}
cout << endl;
cout << "A win games: " << Win_A << endl;
cout << "B win games: " << Win_B << endl;
_getwch();
}
