#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
int play=0;
int com=0;
string name []={"剪刀","石頭","布"};
cout<<"請輸入(1)剪刀(2)石頭(3)布"<<endl;
cin>>play;
cout<<"電腦出拳中..."<<endl;
srand(time(NULL));
com=(rand()%(3))+1;
cout<<"玩家出"<<name[play-1]<<endl;
cout<<"電腦出"<<name[com-1]<<endl;
cout<<"結果"<<endl;
if(com==play)
{
cout<<"平手"<<endl;
}
if(com==2&&play==1)
{
cout<<"電腦獲勝"<<endl;
}
if(com==3&&play==2)
{
cout<<"電腦獲勝"<<endl;
}
if(com==1&&play==3)
{
cout<<"電腦獲勝"<<endl;
}
if(com==1&&play==2)
{
cout<<"玩家獲勝"<<endl;
}
if(com==2&&play==3)
{
cout<<"玩家獲勝"<<endl;
}
if(com==3&&play==1)
{
cout<<"玩家獲勝"<<endl;
}
system("pause");
return 0;
} |