#include #include int CHANCE,FIRST,MODEL,ANSWER; long LASTGET,WANTGET,SUMAPPLE,FIBONACI[46]; void INITIAL(); long FIBFUNCTION(int SUM); void GAME(); void PERSON(); void RESULT(); void MACHINESLOW(); void MACHINEQUICK(); int GETMINFIB(int CURRENTAPPLES); int main(void) {printf("ID: 2013304107\n"); INITIAL(); GAME(); getch(); RESULT(); getch(); return 0; } long FIBFUNCTION(int NUM) { long FIB1=1,FIB2=1,FIB3; int CIRCLE; if(NUM<=1)return 1; for(FIB3=FIB1+FIB2,CIRCLE=2;CIRCLE=1):"); scanf("%ld",&SUMAPPLE); printf("\n---Please take the chance(0---YOU FIRST/1---I FIRST):"); scanf("%d",&CHANCE); printf("\n---Please take the type(0---SLOW MODEL/1---QUICK MODEL):"); scanf("%d",&MODEL); if(SUMAPPLE>1) printf("\n---The first time both of us can only choose 1-%ld\n",SUMAPPLE-1); else printf("\n---The first time both of us can only choose 1!\n"); for(circle=0;circle<46;circle++) FIBONACI[circle]=FIBFUNCTION(circle); FIRST=1; LASTGET=0; } int GETMINFIB(int CURRENTAPPLES) { int circle=45,FOUND=0; while((circle>=0)&&(FOUND==0)) { while(CURRENTAPPLES2*LASTGET)&&(!FIRST))WANTGET=1; LASTGET=WANTGET; SUMAPPLE=SUMAPPLE-WANTGET; printf("\n*****I get %ld apples .\n",LASTGET); printf("\n-----The Current Apples are:%ld\n",SUMAPPLE); CHANCE=0; FIRST=0; if(SUMAPPLE==0)printf("\n****I win the GAME!"); ANSWER=0; } void MACHINEQUICK() { int TRY1,TRY2; TRY1=TRY2=SUMAPPLE; WANTGET=GETMINFIB(SUMAPPLE); if((FIRST)&&(SUMAPPLE==1))WANTGET=1; while((FIRST)&&(WANTGET*2<(SUMAPPLE-WANTGET))) { TRY1=TRY1-GETMINFIB(TRY1); WANTGET=WANTGET+GETMINFIB(TRY1); if(WANTGET*2>GETMINFIB(SUMAPPLE-WANTGET)) { WANTGET=WANTGET-GETMINFIB(TRY1); break; } } if(((FIRST)&&((SUMAPPLE-GETMINFIB(SUMAPPLE))==0))&&(SUMAPPLE!=1)) WANTGET=WANTGET+1; if((WANTGET>2*LASTGET)&&(!FIRST))WANTGET=1; while((!FIRST)&&((WANTGET*2)<(SUMAPPLE-WANTGET))&&(WANTGET<=2*LASTGET)) { TRY2=TRY2-GETMINFIB(TRY2); WANTGET=WANTGET+GETMINFIB(TRY2); } if((FIRST)&&(WANTGET!=0)&&(SUMAPPLE-WANTGET<=WANTGET*2)) WANTGET=WANTGET-GETMINFIB(TRY2); if((WANTGET!=1)&(!FIRST))WANTGET=WANTGET-GETMINFIB(TRY2); if(WANTGET==0)WANTGET=WANTGET+GETMINFIB(TRY2); if((SUMAPPLE<=LASTGET*2)&&(!FIRST)) { WANTGET=SUMAPPLE; SUMAPPLE=0; } LASTGET=WANTGET; if(SUMAPPLE!=0)SUMAPPLE=SUMAPPLE-WANTGET; if((SUMAPPLE+WANTGET)==GETMINFIB(SUMAPPLE+WANTGET)&&(SUMAPPLE>LASTGET*2)) { SUMAPPLE=SUMAPPLE+WANTGET-1; LASTGET=1; } printf("\n*****I get %ld apples.\n",LASTGET); printf("\n-----The Current Apples are:%ld\n",SUMAPPLE); ANSWER=0; } void PERSON() { printf("\n*****The apples you want to get:"); scanf("%ld",&WANTGET); if(FIRST) { if(SUMAPPLE==1) { while(WANTGET!=1) { printf("\n-----You are cheated!\n"); printf("\nThe apples you want to get:"); scanf("%ld",&WANTGET); } } if(SUMAPPLE>1) { while((WANTGET>=SUMAPPLE)||(WANTGET<=0)) { printf("\n-----You are cheated!\n"); printf("\nThe apples you want to get:"); scanf("%ld",&WANTGET); } } FIRST=0; } else { while((WANTGET>2*LASTGET)||(WANTGET<=0)||(WANTGET>SUMAPPLE)) { printf("\n-----You are cheated!\n"); printf("\nThe apples you want to get:"); scanf("%ld",&WANTGET); } } SUMAPPLE=SUMAPPLE-WANTGET; LASTGET=WANTGET; CHANCE=1; printf("\n-----You get %ld apples.\n",LASTGET); if(SUMAPPLE==0)printf("\n*****You win the GAME!"); ANSWER=1; } void GAME() { while(SUMAPPLE>0) { if((CHANCE==1)&&(MODEL==0)&&(SUMAPPLE!=0))MACHINESLOW(); if((CHANCE==1)&&(MODEL==1)&&(SUMAPPLE!=0))MACHINEQUICK(); if((CHANCE==0)&&(SUMAPPLE!=0))PERSON(); } } void RESULT() { if(ANSWER==1)cprintf("\nCongratulations !\n"); else cprintf("\nYou lose the Game,Try again!\n"); cprintf("DESIGNED BY NEW TRUMP\n"); }