1256HDU

一道比较简单的画图题,将一个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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值