5种不同颜色球取出3个不同颜色球的取法 用C++编写

5种不同颜色球取出3个不同颜色球的取法 用C++编写


#include
#include
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< }
else
continue;
}
}
else
continue;
}
}
}

怎样才能把输出的文字搞得像图中那么整齐
miaomiao_nl 1年前 已收到1个回答 举报

月照千井 幼苗

共回答了17个问题采纳率:88.2% 举报

计算字符串长度.然后加多少空格就可以了.比如一行的总字符串长度定为100个.那个第一个字符串肯定是从0起始,第二个字符串定义从30起,第三个字符串定义从80起.大概这样

1年前 追问

1

miaomiao_nl 举报

求具体代码

举报 月照千井

#include "stdafx.h"

#include

#include

#include

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<

<

cout<

<

}

system("pause");

return 0;

}

这种效果吧

可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 17 q. 0.364 s. - webmaster@yulucn.com