3个回答
展开全部
vc6:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int win[][3] = {
{0, -1, 1},
{1, 0, -1},
{-1, 1, 0}
};
char *s[] = {"剪刀", "石头", "布"};
char *r[] = {"你输了", "平局", "你赢了"};
int rnd(int min, int max)
{
static int a = 1;
if( a )
{
srand(time(NULL));
a = 0;
}
return rand()/(double)RAND_MAX * (max-min+1) + min;
}
int main(int argc, char *argv[])
{
int a;
int b;
do{
cout<<"你出(1.剪刀 2.石头 3.布):";
cin>>a;
a--;
if( a>=0 && a<3 )
{
b = rnd(0, 2);
cout<<"电脑出"<<s[b]<<endl;
cout<<r[win[a][b]+1]<<endl;
}
}while(a>=0 && a<3);
return 0;
}
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int win[][3] = {
{0, -1, 1},
{1, 0, -1},
{-1, 1, 0}
};
char *s[] = {"剪刀", "石头", "布"};
char *r[] = {"你输了", "平局", "你赢了"};
int rnd(int min, int max)
{
static int a = 1;
if( a )
{
srand(time(NULL));
a = 0;
}
return rand()/(double)RAND_MAX * (max-min+1) + min;
}
int main(int argc, char *argv[])
{
int a;
int b;
do{
cout<<"你出(1.剪刀 2.石头 3.布):";
cin>>a;
a--;
if( a>=0 && a<3 )
{
b = rnd(0, 2);
cout<<"电脑出"<<s[b]<<endl;
cout<<r[win[a][b]+1]<<endl;
}
}while(a>=0 && a<3);
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <iostream>
#include <math.h>
#include <time.h>
using namespace std;
enum fist_type{stone,scissors,cloth,number};
char* fist_str[]={"stone","scissors","cloth"};
enum fist_chktype{you_win,you_draw,you_lose};
char* fist_chk[]={"You win!","You draw!","You lose!"};
int computer(void)
{
srand((unsigned)time(NULL));
return rand()%number;
}
int check(int me,int com)
{
if(me==com)return you_draw;
if(abs(me-com)==1)
{
if(me<com)return you_win;
else return you_lose;
}
if(me==cloth)return you_win;
else return you_lose;
}
int main(void)
{
int i;
while(1)
{
cout<<"1.stone"<<endl;
cout<<"2.scissors"<<endl;
cout<<"3.cloth"<<endl;
cout<<"input(enter other number to exit!):";
cin>>i;i--;
if(i!=0 && i!=1 && i!=2)break;
int c=computer();
cout<<"You:"<<fist_str[i]<<endl;
cout<<"Computer:"<<fist_str[c]<<endl;
cout<<fist_chk[check(i,c)]<<endl;
cout<<endl;
}
return 0;
}
#include <math.h>
#include <time.h>
using namespace std;
enum fist_type{stone,scissors,cloth,number};
char* fist_str[]={"stone","scissors","cloth"};
enum fist_chktype{you_win,you_draw,you_lose};
char* fist_chk[]={"You win!","You draw!","You lose!"};
int computer(void)
{
srand((unsigned)time(NULL));
return rand()%number;
}
int check(int me,int com)
{
if(me==com)return you_draw;
if(abs(me-com)==1)
{
if(me<com)return you_win;
else return you_lose;
}
if(me==cloth)return you_win;
else return you_lose;
}
int main(void)
{
int i;
while(1)
{
cout<<"1.stone"<<endl;
cout<<"2.scissors"<<endl;
cout<<"3.cloth"<<endl;
cout<<"input(enter other number to exit!):";
cin>>i;i--;
if(i!=0 && i!=1 && i!=2)break;
int c=computer();
cout<<"You:"<<fist_str[i]<<endl;
cout<<"Computer:"<<fist_str[c]<<endl;
cout<<fist_chk[check(i,c)]<<endl;
cout<<endl;
}
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<windows.h>
#include<iostream>
using namespace std;
class Play
{
public:
int People;
unsigned long Computer;
public:
Play(){};
~Play(){};
void Set_People(int _p)
{
People=_p;
}
void Set_Computer(unsigned long _C)
{
Computer=_C;
}
int Judge()
{
switch(People)
{
case 0:
cout<<"你所选择的是石头 :";
break;
case 1:
cout<<"你所选择的是剪刀 :";
break;
case 2:
cout<<"你所选择的是布 :";
break;
}
switch(Computer)
{
case 0:
cout<<"电脑选择的是石头";
break;
case 1:
cout<<"电脑选择的是剪刀";
break;
case 2:
cout<<"电脑选择的是布";
break;
}
cout<<endl;
if(People+1==Computer || People-2==Computer)
return 1;
if(People==Computer)
return 0;
return -1;
}
};
void main()
{
Play play;
int a=5;
int failure=0,win=0,tie=0;
unsigned long begin;
while(a!=-1)
{
begin=GetTickCount();
cout<<"****************** 请选择 *******************"<<endl;
cout<<"*********0石头 1剪刀 2布 -1退出**********"<<endl;
cout<<"请输入 :";
cin>>a;
system("cls");
if(a<=2 && a>-1)
{
play.Set_People(a);
play.Set_Computer(begin%3);
switch(play.Judge())
{
case 1:
cout<<"恭喜你赢了"<<endl;
win++;
break;
case 0:
cout<<"你未获胜,请继续"<<endl;
tie++;
break;
case -1:
cout<<"不幸,你输了了"<<endl;
failure++;
break;
}
}
else
{
if(a!=-1)
cout<<"选择错误 ,请重新选择"<<endl;
}
}
cout<<"你总共下了: "<<failure+win+tie<<"次 "<<"你赢了: "<<win<<"次 "<<"输了:"<<failure<<"次 "<<"平局:"<<tie<<"次"<<endl;
}
#include<iostream>
using namespace std;
class Play
{
public:
int People;
unsigned long Computer;
public:
Play(){};
~Play(){};
void Set_People(int _p)
{
People=_p;
}
void Set_Computer(unsigned long _C)
{
Computer=_C;
}
int Judge()
{
switch(People)
{
case 0:
cout<<"你所选择的是石头 :";
break;
case 1:
cout<<"你所选择的是剪刀 :";
break;
case 2:
cout<<"你所选择的是布 :";
break;
}
switch(Computer)
{
case 0:
cout<<"电脑选择的是石头";
break;
case 1:
cout<<"电脑选择的是剪刀";
break;
case 2:
cout<<"电脑选择的是布";
break;
}
cout<<endl;
if(People+1==Computer || People-2==Computer)
return 1;
if(People==Computer)
return 0;
return -1;
}
};
void main()
{
Play play;
int a=5;
int failure=0,win=0,tie=0;
unsigned long begin;
while(a!=-1)
{
begin=GetTickCount();
cout<<"****************** 请选择 *******************"<<endl;
cout<<"*********0石头 1剪刀 2布 -1退出**********"<<endl;
cout<<"请输入 :";
cin>>a;
system("cls");
if(a<=2 && a>-1)
{
play.Set_People(a);
play.Set_Computer(begin%3);
switch(play.Judge())
{
case 1:
cout<<"恭喜你赢了"<<endl;
win++;
break;
case 0:
cout<<"你未获胜,请继续"<<endl;
tie++;
break;
case -1:
cout<<"不幸,你输了了"<<endl;
failure++;
break;
}
}
else
{
if(a!=-1)
cout<<"选择错误 ,请重新选择"<<endl;
}
}
cout<<"你总共下了: "<<failure+win+tie<<"次 "<<"你赢了: "<<win<<"次 "<<"输了:"<<failure<<"次 "<<"平局:"<<tie<<"次"<<endl;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询