PAT B 1036 (C ++) - Long brush brother's title path

Obama 1036 together with the programming (15 points)
US President Barack Obama not only appeal to everyone to learn programming, and even set an example to write code, write computer code to become the first president in American history. The end of 2014, to celebrate the "Computer Science Education Week" was officially launched, Obama wrote the computer code is very simple: draw a square on the screen. Now you draw it with him!

Input format:
input given square side length N (3≤N≤20) square sides and composition C in a certain line of characters, a space interval.

Output format:
Output the character C is drawn by a given square. But noted that the line spacing is larger than the column spacing, so in order to make the results look more like a square, the number of lines we output is actually 50% of the number of columns (rounded to the nearest integer).

Sample input:
10 A

Sample output:
Here Insert Picture Description

#include<cstdio>
int main(){
	int n=0;
	char c=' ';
	scanf("%d %c",&n,&c);
	int N = (int)(n / 2.0 + 0.5);
	for (int i = 0; i < N; i++){
		if (i == 0 || i == N - 1){
			for (int i = 0; i < n; i++){
				printf("%c",c);
			}
			printf("\n");
		}
		else{
			printf("%c", c);
			for (int i = 0; i < n - 2; i++){
				printf(" ");
			}
			printf("%c", c);
			printf("\n");
		}
	}
	return 0;
}
Published 46 original articles · won praise 0 · Views 586

Guess you like

Origin blog.csdn.net/qq_23079139/article/details/104101356