1036. 跟奥巴马一起编程(15)

https://www.patest.cn/contests/pat-b-practise/1036

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,col,row,t1;
	double t2;
	char c;
	scanf("%d %c",&n,&c);
	
	t1 = n/2;
	t2 = n*1.0/2;
	if(t2-t1<0.5)	row = n/2;
	else row = n/2 + 1; 
	
	col = n;
	for(int i = 0;i < row; i++)
	{
		if(i == 0||i == row-1)
		{
			for(int j = 0;j < n; j++)
			{
				printf("%c",c);
				if(j == col-1) printf("\n");
			} 
		}
		else {
			for(int j = 0;j < n; j++)
			{
				if(j == 0 || j == col-1)printf("%c",c);
				else printf(" ");
				if(j == col-1)	printf("\n");
			}
		}
	}
	return 0;
} 

  

posted on 2018-02-14 16:05  七昂的技术之旅  阅读(181)  评论(0编辑  收藏  举报

导航