您好,登錄后才能下訂單哦!
口袋中有5種顏色的小球,每次從口袋中任意取3個,問得到3種不同顏色的小球的可能取法?
#define _CRT_SECURE_NO_WARNINGS 1 #include<iostream> #include<iomanip> using namespace std; int main() { enum color{red,yellow,blue,white,black};//聲明枚舉類型color color pri; //定義color類型的變量pri int i, j, k,n = 0, loop; //n是累計不同顏色的組合數 for (i = red; i <= black; i++) { for (j = red; j <= black;j++) if (i != j) { for (k = red; k <= black;k++) if ((k != i) && (k != j)) { n = n + 1; cout << setw(3) << n; for (loop = 1; loop <= 3; loop++) { switch (loop) { case 1:pri = color(i); break; case 2:pri = color(j); break; case 3:pri = color(k); break; defaul:break; } switch (pri)//判斷pri的值,輸出相應的"顏色" { case red:cout << setw(8) << "red"; break; case yellow:cout << setw(8) << "yellow"; break; case blue:cout << setw(8) << "blue"; break; case white:cout << setw(8) << "white"; break; case black:cout << setw(8) << "black"; break; default:break; } } cout << endl; } } } cout << "total:" << n << endl;//輸出符合條件的組合的個數 getchar(); return 0; }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。