PAT B1036 programmed together with Obama (15 points)

1036 programming together with Obama (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 formats:

Input gives the square side length N (3≤N≤20) in a row and consisting of one of the character square edges C, a space interval.

Output formats:

C output from the given character drawn 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:

aaaaaaaaaa
a        a
a        a
a        a
aaaaaaaaaa

I did not understand the meaning of the title, until you see the algorithm notes ~

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;

int main(){
	int n;
	char a;
	cin>>n>>a;
	for(int i=0;i<n;i++){
		cout<<a;
		if(i==(n-1)){
			cout<<endl;
		}
	}
	int row;
	if(n%2==0){
		row=n/2-2;
	}
	else {
		row=(n-1)/2-1;
	}
	for(int i=0;i<row;i++){
		cout<<a;
		for(int t=0;t<n-2;t++){
			cout<<" ";
		}
		cout<<a<<endl;
	}
	for(int i=0;i<n;i++){
		cout<<a;
	}
	return 0; 
}

 

Published 10 original articles · won praise 1 · views 718

Guess you like

Origin blog.csdn.net/chf2015005328/article/details/104097154