5种不同颜色球取出3个不同颜色球的取法 用C++编写
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/07/17 07:30:25
5种不同颜色球取出3个不同颜色球的取法 用C++编写
#include <iostream>
#include <iomanip>
using namespace std;
void main()
{
int i,j,k,n=0;
for(i=1;i<=3;i++)
{
for(j=i+1;j<=5;j++)
{
if(j!=i)
{
for(k=j+1;k<=5;k++)
{
if(k!=i&&k!=j)
{
cout<<++n<<endl;
}
else
continue;
}
}
else
continue;
}
}
}
怎样才能把输出的文字搞得像图中那么整齐
#include <iostream>
#include <iomanip>
using namespace std;
void main()
{
int i,j,k,n=0;
for(i=1;i<=3;i++)
{
for(j=i+1;j<=5;j++)
{
if(j!=i)
{
for(k=j+1;k<=5;k++)
{
if(k!=i&&k!=j)
{
cout<<++n<<endl;
}
else
continue;
}
}
else
continue;
}
}
}
怎样才能把输出的文字搞得像图中那么整齐
计算字符串长度.然后加多少空格就可以了.比如一行的总字符串长度定为100个.那个第一个字符串肯定是从0起始,第二个字符串定义从30起,第三个字符串定义从80起.大概这样
再问: 求具体代码
再答: #include "stdafx.h"#include <iostream>#include <iomanip>#include <string>using namespace std;int _tmain(int argc, _TCHAR* argv[]){string ball_color[5] = {"red","yellow","blue","white","black"};//最多5个字节。就以10个字节为一组进行对齐string space_str = " ";//8个空格for (int i=0;i<5;i++){cout<<ball_color[i%5]<<space_str.substr(0,space_str.length()-ball_color[i%5].length())<<ball_color[(i+1)%5]\<<space_str.substr(0,space_str.length()-ball_color[(i+1)%5].length())<<ball_color[(i+2)%5]<<endl;cout<<ball_color[i%5]<<space_str.substr(0,space_str.length()-ball_color[i%5].length())<<ball_color[(i+2)%5]\<<space_str.substr(0,space_str.length()-ball_color[(i+2)%5].length())<<ball_color[(i+3)%5]<<endl;}system("pause");return 0;}这种效果吧
再问: 求具体代码
再答: #include "stdafx.h"#include <iostream>#include <iomanip>#include <string>using namespace std;int _tmain(int argc, _TCHAR* argv[]){string ball_color[5] = {"red","yellow","blue","white","black"};//最多5个字节。就以10个字节为一组进行对齐string space_str = " ";//8个空格for (int i=0;i<5;i++){cout<<ball_color[i%5]<<space_str.substr(0,space_str.length()-ball_color[i%5].length())<<ball_color[(i+1)%5]\<<space_str.substr(0,space_str.length()-ball_color[(i+1)%5].length())<<ball_color[(i+2)%5]<<endl;cout<<ball_color[i%5]<<space_str.substr(0,space_str.length()-ball_color[i%5].length())<<ball_color[(i+2)%5]\<<space_str.substr(0,space_str.length()-ball_color[(i+2)%5].length())<<ball_color[(i+3)%5]<<endl;}system("pause");return 0;}这种效果吧
口袋中有红,黄,蓝,白,黑5种颜色的球若干个.每次从口袋中取出3个不同颜色的球,问有多少种取法.用c++
口袋中有红,黄,蓝,白,黑5中颜色的球若干个,每次从口袋里取出5个不同颜色的球,问有多少种取法.
口袋有红黄蓝白黑5种颜色的球若干个,每次从口袋中取出3个不同颜色的球,问有多少种取法?这是排列还是组合
小明口袋内有三种颜色的球各三个,每次取出三个不同颜色的球,有几种取法
口袋中有红、黄、蓝、白四种颜色的球若干,每次从口袋里取出2种不同颜色的球,问有多少种取法.
口袋中有红黄蓝白黑5种颜色的球,每次从中取3个球,问得到的3种不同颜色的球的可能取法,输出每种排列情况?(我刚学到结构体
袋子里有红、蓝、黄、白各40个,至少取出多少个,才能保证有4种不同颜色的球
怎么计算从10个不同颜色球中取出条件球的概率呢?
布袋中有足够多的5种不同颜色地球,最少取出多少个球才能保证其中一定有2个颜色一样的球?
一个袋子里面放了3种不同颜色的球共20个,其中8个白色的,7个红色的,5个绿色的.如果闭上眼睛从袋子里取出球,要求袋子中
口袋中有红、黄、蓝、白、黑5种颜色的5只小球,每次从口袋中取出3只球,问:最多有几种不同颜色的组合.
口袋中有红、黄、蓝、白、黑五种颜色的球若干个,每次从口袋中取三个不同颜色的球,统计并输出所有的取法