# 【題解】APCS1090105-1 猜拳模擬

【題目敘述】http://judge.epass2u.com/problem/APCS1090105-1 (無法使用)
【解題想法】模擬

• 函式 scoring( )：計分
• 函式 Next( )：決定程式的下一拳
```#include <iostream>
#include <vector>
using namespace std;
int x, N;
int a[11];

int scoring(int nana){
if (nana == x) return 0;
if (nana == 0){
if (x == 2) return 1;
else return -1;
} else if (nana == 2){
if (x == 5) return 1;
else return -1;
} else {
if (x == 0) return 1;
else return -1;
}
}

int Next(int n0, int n1){
if (n0 == n1){
if (n0 == 0) return 5;
else if (n0 == 2) return 0;
else return 2;
} else {
return n1;
}
}

int main() {
while (cin >> x >> N){
for (int i=0; i<N; i++){
cin >> a[i];
}
int score = scoring(a[0]);
int round = 1;
vector <int> v;
v.push_back(x);
while (round < N && score == 0){
if (round >= 2) x = Next(a[round-2], a[round-1]);
else x = a[round-1];
score += scoring(a[round]);
v.push_back(x);
round++;
}

for (auto i : v) cout << i << ' ';
if (score > 0) cout << ": Won at round " << round << '\n';
else if (score < 0) cout << ": Lost at round " << round << '\n';
else cout << ": Drew at round " << round << '\n';
}
return 0;
}
```

Python code (credit: Amy Chou)

```def scoring(nana):
if nana == x: return 0
if nana == 0:
if x == 2:
return 1
else:
return -1
elif nana == 2:
if x == 5:
return 1
else: return -1
else:
if x == 0:
return 1
else:
return -1

def Next(n0, n1):
if n0 == n1:
if n0 == 0:
return 5
elif n0 == 2:
return 0
else:
return 2
else:
return n1

# main program
x = int(input())
N = int(input())
a = list(map(int, input().split()))

score = scoring(a[0])
Round = 1
v = [x]
while (Round < N and score == 0):
if Round >= 2:
x = Next(a[Round - 2], a[Round - 1])
else:
x = a[Round - 1]

score += scoring(a[Round])
v.append(x)
Round += 1

for i in range(len(v)):
print(v[i], ' ', sep='', end='')

if score > 0:
print(": Won at round", Round)
elif score < 0:
print(": Lost at round", Round)
else:
print(": Drew at round", Round)
```