一道比较简单的画图题,将一个8拆解成5个部分就会很好理解
- 头部,只有一行
- 上半圆圈
- 中部,只有一行
- 下半圆圈
- 尾部,只有一行
- 其中,头部,中部,尾部完全一样
- 需要注意的点:每一行最后一个字符后面没有空格,这也是基本的格式控制
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
char c;
int a;
while(n--)
{
cin>>c>>a;
//计算下半圆圈的高度,同时也是头,中,尾三个部分的宽度
int down=((a-3)%2)==0?(a-3)/2:(a-3)/2+1;
//上半圆圈的高度
int up=a-3-down;
//竖线的宽度
int width=a/6+1;
//画头部
for(int i=0;i<width;i++)
cout<<" ";
for(int i=0;i<down;i++)
cout<<c;
cout<<endl;
//画上半圆圈
for(int i=0;i<up;i++)
{
for(int j=0;j<width;j++)
cout<<c;
for(int j=0;j<down;j++)
cout<<" ";
for(int j=0;j<width;j++)
cout<<c;
cout<<endl;
}
//中部
for(int i=0;i<width;i++)
cout<<" ";
for(int i=0;i<down;i++)
cout<<c;
cout<<endl;
//下半圆圈
for(int i=0;i<down;i++)
{
for(int j=0;j<width;j++)
cout<<c;
for(int j=0;j<down;j++)
cout<<" ";
for(int j=0;j<width;j++)
cout<<c;
cout<<endl;
}
//尾部
for(int i=0;i<width;i++)
cout<<" ";
for(int i=0;i<down;i++)
cout<<c;
cout<<endl;
if(n)
cout<<endl;
}
return 0;
}