码迷,mamicode.com
首页 > 其他好文 > 详细

杭电1256——画8

时间:2015-04-27 23:48:19      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:acm   杭电   

这题很简单,算出第一行有几个,和竖线宽度就OK了。

知道了竖线宽度和第一行有几个字符,剩下的都很简单了。

下面是AC代码:

#include <iostream>
using namespace std;

int main()
{
	int n, m;
	char a;
	cin >> n;
	while(n--)
	{
		int i, j;
		cin >> a >> m;
		int q = (m - 2) / 2;            //第一行有几个字符的规律。
		int p = (m + 6) / 6;            //竖线宽度
		for(i = 0; i < (m  - 1) / 2; i++)
		{
			if(i == 0)
			{
				for(j = 0; j < p; j++)
					cout << ' ';
				for(j = 0; j < q; j++)
					cout << a;
				cout << endl;
			}
			else
			{
				for(j = 0; j < p; j++)
					cout << a;
				for(j = 0; j < q; j++)
					cout << ' ';
				for(j = 0; j < p; j++)
					cout << a;
				cout << endl;
			}
		}
		for(i = 0; i < (m - 1) - (m  - 1) / 2; i++)
		{
			if(i == 0)
			{
				for(j = 0; j < p; j++)
					cout << ' ';
				for(j = 0; j < q; j++)
					cout << a;
				cout << endl;
			}
			else
			{
				for(j = 0; j < p; j++)
					cout << a;
				for(j = 0; j < q; j++)
					cout << ' ';
				for(j = 0; j < p; j++)
					cout << a;
				cout << endl;
			}
		}
		for(i = 0; i < p; i++)
			cout << ' ';
		for(j = 0; j < q; j++)
			cout << a;
		cout << endl;
		if(n != 0)
			cout << endl;
	}
	return 0;
}

杭电1256——画8

标签:acm   杭电   

原文地址:http://blog.csdn.net/qq_25425023/article/details/45317557

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!