请大神用C语言写出这个数据结构题的源代码!

如题所述

第1个回答  2015-10-09
#include<iostream>
#include<windows.h>
#include<process.h>
using namespace std;

int flag = 0;//控制是否停止击鼓
int i = 0;//控制花在谁手里
int n;//游戏人数
int stopgameflag = 0;//是否结束游戏
{
while(!stopgameflag)
{
while(flag == 0)
{
i++;
if (i == n)
{
i = 0;
}
}
Sleep(10);
}
return 1;
}
int main()
{
char str[20] = {0};
cout<<"请输入参加游戏人数:";
cin>>n;
HANDLE hThread;
unsigned threadID;

hThread = (HANDLE) _beginthreadex(NULL, 0, Threadforflower, NULL, 0, &threadID);
if (hThread == NULL)
{
cout<<"传花线程创建失败!!"<<endl;
return 0;
}
cout<<"传花线程创建成功!!(按下字符s键并回车时,停止击鼓, 输入over并回车时结束游戏,输入其他则重新击鼓)"<<endl;
while(1)
{
cout<<"开始击鼓..."<<endl;
fflush(stdin);
cin>>str;
if (!strcmp(str , "over") || !strcmp(str , "OVER"))
{
flag = 1;
stopgameflag = 1;
break;
}
if (!strcmp(str, "s") || !strcmp(str , "S"))
{
flag = 1;
cout<<"花在第"<<i<<"个人手中"<<endl;
flag = 0;
}
}
WaitForSingleObject(hThread, INFINITE );
cout<<"游戏结束"<<endl;
return 0;
}追问

错误!

追答

你试了?

追问

嗯。完全错误

本回答被网友采纳