杭电1256——画八

杭电1256——画8

这题很简单,算出第一行有几个,和竖线宽度就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;
}