Move Mountain Game

Source: Internet
Author: User

Problem

With N-Mount Mountain, computer and people as the two sides, take turns to move the mountain, the provisions of each move mountain number not more than K, who moved the last mountain who loses.

#include <stdio.h> #include <stdlib.h>/* run this program using the console Pauser or add your own getch, syste M ("pause") or input loop */int main (int argc, char *argv[]) {int n, k, x, Y, CC, PC, g;printf ("More Mountain game\n");p Rin TF ("Game begin\n");p c = cc = 0;g = 1;for (;;) {printf ("no.%2d Game \ n", g++);p rintf ("-------------\ n");p rintf ("How many mo Ntains is there? "); scanf ("%d", &n), if (!n) break;printf ("How many montains is allow for each time?"); DO{SCANF ("%d", &k); if (K>n | | k<1) printf ("Repeat again!\n");}  while (K>n | | k<1);d O//This is the person's move Mountain method {printf ("How many montains does you wish move Away"); scanf ("%d", &x); if (x<1 | | x>k | | X>n) {printf ("Iiiegal, again please!\n"); continue;} N-= x;printf ("There is%d Montains left now.\n", N), if (!n) {printf ("... I win"). You are fail.....\n\n "); cc++;} else//This is the move mountain method of the machine {y = (n-1)% (k+1);//Key algorithm if (!y) y=1;n-=y;printf ("Computer move%d montiains away.\n", y); if (n) printf (" There is%d mountains left now.\n ", N); else{pRintf ("...... I am fail. You win\n\n ");p C + +;}}} while (n);} printf ("Total has played%d.\n", cc+pc);p rintf ("You score are win%d, lose%d.\n", PC, CC);p rintf ("You score is win%d, Lo Se%d.\n ", CC, PC); return 0;} /*more Mountain gamegame Beginno. 1 game-------------How many montains is there?10how many montains is allow to each time?3how many montains does you wish M Ove Away3there is 7 Montains left now. Computer move 2 montiains away. There is 5 mountains left now.how many montains does you wish move Away2there is 3 montains left now. Computer move 2 montiains away. There is 1 mountains left now.how Many montains does you wish move Away1there is 0 Montains left now........i win. You are fail ..... No. 2 game-------------how many Montains is There?0total has played 1.you score is win 0, lose 1.you score is win 1, Los E 0.*/


Move Mountain Game

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.