C++作业
口袋中有红,黄,蓝,白,黑5种颜色的球若干个,每次从口袋中取出三个不同颜色的球,问有几种取法,要弄到enum函数,这道题要求一次取出3种颜色而不是一个个的取,求帮忙啊
[解决办法]
#include <iostream>#include <string>using namespace std;int main(){ enum colors{red,yellow,white,blue,black}; string col[5]={"红","黄","白","蓝","黑"}; int n=0; for(int i=red;i<=black;i++) { for(int j=i+1;j<=black;j++) { for(int k=j+1;k<=black;k++) { cout<<col[i]<<' '; cout<<col[j]<<' '; cout<<col[k]<<endl; n++; } } } cout<<"一共有"<<n<<"种取法。"<<endl; return 0;}