用c++打印这个图形

来源:百度知道 编辑:UC知道 时间:2024/05/20 00:14:40
stststststststststststs
ststststststststststs
stststststststststs
ststststststststs
stststststststs
ststststststs
stststststs
.
.
.
sts
s
总共10行,中间ST的我省略了没有写
我的代码写到这里
#include<iostream>
using namespace std;
int main()
{
int i,j,k;
for(i=1;i<=10;i++)
{
for(j=1;j<=i-1;j++)
cout<<" ";
for(k=1;k<=21-2*i;k++)//这里的代码写错了,我不知道怎么才能输出一个S在输出一个T,还请高手给我讲下怎么才才能实现//
cout<<"S";
cout<<"T";
}
return 0;
}

#include<iostream>
using namespace std;
int main()
{
int i,j,k;
for(i=1;i<=10;i++)
{
for(j=1;j<i;j++)
cout<<" ";
for(k=1;k<=11-i;k++)
cout<<"ST";
cout<<"S"<<endl;
}
return 0;
}

#include <iostream>

int main()
{
using namespace std;

const int length=10;
bool b=true;

for(int i=1;i<=length;++i)
{
for(int n=length-i;n>=1;--n)
cout<<' '; //前面空格

for(int j=1;j<=2*i-1;++j)
{
if(b)
{
cout<<'s';
}
else
{
cout<<'t';
}
b=!b;
}
cout<<endl;
b=true;
}
return 0;
}