- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- re:
- srand(time(NULL));
- int p,c;
- string a[]{"剪刀","石頭","布"};
- cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
- cin>>p;
- c=rand()%3+1;
- cout<<"你出"<<a[p-1]<<endl;
- cout<<"電腦出"<<a[c-1]<<endl;
- if(p==c)
- {
- cout<<"平手"<<endl<<endl;
- }
- else if(p==1&&c==2)
- {
- cout<<"電腦贏了"<<endl<<endl;
- }
- else if(p==2&&c==3)
- {
- cout<<"電腦贏了"<<endl<<endl;
- }
- else if(p==1&&c==3)
- {
- cout<<"你贏了"<<endl<<endl;
- }
- else if(p==2&&c==1)
- {
- cout<<"你贏了"<<endl<<endl;
- }
- else if(p==3&&c==2)
- {
- cout<<"你贏了"<<endl<<endl;
- }
- else if(p==3&&c==1)
- {
- cout<<"電腦贏了"<<endl<<endl;
- }
- else
- cout<<"error"<<endl<<endl;
- goto re;
- system("pause");
- return 0;
- }
複製代碼 |