#include <bits/stdc++.h> using namespace std; int main() { int F, N; int ab=0; int a[N];
直接將猜拳順序輸入儲存
cin >> F >> N; for (int i=0; i<N; i++){ cin >> a[i]; // 妹妹預先出的拳 }
使用迴圈檢查
for (int i=0; i<N; i++){ if (a[i-2]==a[i-1]){
簡單條件判斷
if (a[i-1]==0) // 如果妹妹前兩次出石頭 { F = 5; cout << F<< " ";} else if (a[i-1]==2) // 如果妹妹前兩次出剪刀 { F = 0; cout << F<< " ";} else if (a[i-1]==5) // 如果妹妹前兩次出布 { F = 2; cout << F<< " ";} }else{cout << F<< " ";} if((a[i]==0 && F==2) || (a[i]==2 && F==5) || (a[i]==5 && F==0)){ cout << ": Lost at round " << i+1; ab = 1; break; } else if ((a[i]==2 && F==0) || (a[i]==5 && F==2) || (a[i]==0 && F==5)){ cout << ": Won at round " << i+1; ab = 1; break; } } if (ab==0) {cout << ": Drew at round "<< N;} return 0; }