/*
This game rule is as follows: the operator first enters an odd number of N (<200) to indicate N stones
Child. Set the computer to Party A, and the operator to Party B. Take stones in turn on both sides, and take 1-3 stones each time.
To the odd number of stones to win.ProgramGive computers more chances to win,
*/
# Include"Stdio. h"
# Include"Conio. h"
Main ()
{
IntTotal;
IntP=0, C=0, Padd, CADD;
Printf ("Total =");
Scanf ("% D",&Total );
Printf ("\ N ***** begin ***** \ n");
Do
{
If (C % 2 = 0 )
{
If (Total > = 3 )
{
CADD = 3 ;
}
Else If (Total > = 1 )
{
CADD = 1 ;
}
}
Else
{
If (Total > = 2 )
{
CADD = 2 ;
}
Else
{
CADD = 1 ;
}
}
Total -= CADD;
C + = CADD;
Printf ( " COMPUTER: % d \ n " , CADD );
If (Total = 0 ) Break ;
Printf ( " % D leave. \ n " , Total );
Printf ( " Person: " );
Scanf ( " % D " , & Padd );
While (Padd > 3 | Padd < 1 | Padd > Total)
{
Printf ( " Error! % D leave. Again: " , Total );
Scanf ( " % D " , & Padd );
}
Total-=Padd;
P+ =Padd;
Printf ("Person: % d \ n", Padd );
}While(Total! =0);
Printf ("\ N ***** end ***** \ n");
Outputresult (p, C );
Getch ();
}
Outputresult (_ pnum, _ cnum)
{
IntPtag, CTAG;
Printf ("---- Result ---- \ n");
Printf ("Person: % d \ n", _ Pnum );
Printf ("COMPUTER: % d \ n", _ Cnum );
Ptag=(_ Pnum%2! =0?1:0);
CTAG=(_ Cnum%2! =0?1:0);
Printf ( " -------- \ N " );
If (Ptag | CTAG) && ! (Ptag && CTAG ))
{
If (Ptag)
{
Printf ( " Person win! " );
}
Else
{
Printf ( " Computer win! " );
}
}
Else
{
Printf ("No one win!");
}
}