Odd game (c)

Source: Internet
Author: User

/*
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!");
}


}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.