欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-05-18 08:50:55
https://www.patest.cn/contests/pat-b-practise/1036 ......

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;
}