#include<bits/stdc++.h>
using namespace std;
int n;
bool pd(string d,int x){
if(d=="1"||d=="2"){
if(x<=n){
return true;
}
}
return false;
}
int main(){
string s[3]={{""},{"one"},{"two"}};
cout<<"The rules of the game: there are a total of n small sticks, one person and one AI take turns to take it, you can take one or two, and if you get the last one, you will be judged to lose, and the order of taking it is determined by AI.\n Please enter the number of sticks:";
cin>>n;
if(n%3==1){
cout<<"AI chooses the next hand.\n Please take it first:";
while(true){
int x;
cin>>x;
if(pd(to_string(x),x)){
n-=x;
if(n==0){
break;
}
cout<<"AI takes "<<s[3-x]<<" small sticks.\nremainder "<<n-3+x<<" small sticks.\n";
n-=3-x;
cout<<"Please pick it up again:";
}
else{
cout<<"There is an incorrect input. Please re-enter:";
}
}
cout<<"You lose!";
}
else{
if(n%3==2){
cout<<"AI chooses to strike first.\nAI extracts one Small sticks.\nRemaining sticks: "<<n-1<<" small sticks.\n"<<"Please draw a stick:";
n--;
while(true){
int x;
cin>>x;
if(pd(to_string(x),x)){
n-=x;
if(n==0){
break;
}
cout<<"AI takes "<<s[3-x]<<" small sticks.\nremainder "<<n-3+x<<" Small sticks.\n";
n-=3-x;
cout<<"Please pick it up again:";
}
else{
cout<<"There is an incorrect input. Please re-enter:";
}
}
cout<<"You lose!";
}
else{
cout<<"AI chooses to strike first.\nAI extracts two Small sticks.\nRemaining sticks: "<<n-2<<" small sticks.\n"<<"Please draw a stick:";
n-=2;
while(true){
int x;
cin>>x;
if(pd(to_string(x),x)){
n-=x;
if(n==0){
break;
}
cout<<"AI takes "<<s[3-x]<<" small sticks.\nremainder "<<n-3+x<<" Small sticks.\n";
n-=3-x;
cout<<"Please pick it up again:";
}
else{
cout<<"There is an incorrect input. Please re-enter:";
}
}
cout<<"You lose!";
}
}
return 0;
}