3C科技 娛樂遊戲 美食旅遊 時尚美妝 親子育兒 生活休閒 金融理財 健康運動 寰宇綜合

Zi 字媒體

2017-07-25T20:27:27+00:00
加入好友
[C/C++ 演算法]-資料結構與演算法(文魁):捉大頭抽籤遊戲的演算法   線上執行結果:http://www.tutorialspoint.com/compile_c_online.php   /* =========== Program Description ========= */ /* 程式名稱 : 4_2.cpp */ /* 演算法名稱:捉大頭抽籤遊戲的演算法 */ /* 輸入:用陣列代表的資料 */ /* mr��最大層編號,mc��最大橫線編號 */ /* 輸出:捉大頭抽籤遊戲的結果 */ /* ========================================= */ // 宣告標頭檔 #include "stdio.h" // 宣告函式原型 // 利用傳址的方式把Array A,B,C,P,M傳進Bighead函式中 // 利用傳值的方式把整數Mr,Mc傳進Bighead函式中 void Bighead(char *A,int *B,int *P,int *M,int mr,int mc); // 利用傳參考的方式把Value1,Value2兩個變數,傳入swap函式中 void swap(int *Value1, int *Value2); void main() { char A[4]={'A','B','C','D'}; int B[4]={0,1,2,3}; int P[4]={0,1,2,3}; int M[4][3]; int mr=3; int mc=2; M[0][0]=1;M[0][1]=0; M[0][2]=1; M[1][0]=0; M[1][1]=1; M[1][2]=0; M[2][0]=1; M[2][1]=0; M[2][2]=0; M[3][0]=0; M[3][1]=0; M[3][2]=1; Bighead(A,B,P,&M[0][0],mr,mc); getchar(); } void Bighead(char *A,int *B,int *P,int *M,int mr,int mc) { int i,j; for(i=0;i<=mr;i++) for(j=0;j<=mc;j++) if(M[i*4+j]==1) swap((B+j),(B+j+1)); for(j=0;j<=mc;j++) printf("The User %d,Name = %C,has the Lucky number %d\n",B[j],A[B[j]],P[j]); } void swap(int *value1,int *value2) { int temp; temp=*value1; *value1=*value2; *value2=temp; }      

本文由jashliaoeuwordpress提供 原文連結

寫了 5860316篇文章,獲得 23313次喜歡
精彩推薦