问题及代码:
/*
*Copyright (c) 2014,烟台大学计算机学院
*ALL right reserved
*文件名;test。cpp
*作者;李莉
*完成日期2014年10月28日
*版本号v1.0
*
*问题描述:根据要求取不同颜色的球
*程序输入:无输入
*程序输出:不同的取球方案
*/
#include <iostream>
using namespace std;
int main()
{
int i,j,k,count=0;
for (i=0;(i>=0)&&(i<=3);i++)
for(j=0;(j>=0)&&(j<=3);j++)
for (k=0;k<=6;k++)
if((i+k+j)==8&&(8-i-j<=6))
{
count++;
cout<<"方案 :"<<count<<":"<<"红球 :"<<i<<";"<<"白球 :"<<j<<";"<<"黑球 :"<<k<<";"<<endl;
}
cout<<endl;
return 0;
}
运行结果: