编程模拟剪刀、石头和布游戏。游戏规则为:剪刀剪纸,石头砸剪刀,布包石头。玩游戏者从键盘输入s(表示剪刀)或r(表示石头)或p(表示布),要求两个游戏者交替输入,计算机给出输赢的信息。
#include<iostream> using namespace std; int main() { char first,second; cout << "First input( s,r or p ):"; cin >> first; cout << "Second input( s,r or p ):"; cin >> second; switch ( first ) { case 's': switch ( second ) { case 's': cout << "Scissor ties scissor." << endl; goto end; case 'r': cout << "Scissor is crushed by rock." << endl; goto end; case 'p': cout << "Scissor cuts paper." << endl; goto end; default : cout << "second input error!" << endl ; goto end; } case 'r': switch ( second ) { case 's': cout << "Rock crushes scissor." << endl; goto end; case 'r': cout << "Rock ties rock." << endl; goto end; case 'p': cout << "Rock is wrapped by paper." << endl; goto end; default : cout << "second input error!" << endl; goto end; } case 'p': switch ( second ) { case 's': cout << "Paper is cut by scissor." << endl; goto end; case 'r': cout << "Paper wraps the rock." << endl; goto end; case 'p': cout << "Paper ties paper." << endl; goto end; default : cout << "second input error!" << endl; goto end; } default : cout << "First input error!" << endl; goto end; } end: ; }
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题