PAT Basic 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:

In the given input row square side length  N ( . 3) consisting of a square side and one of the character C, a space interval.

Output formats:

C output from the given character drawn square. But he 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



#include <iostream>
using namespace std;
int main()
{
    int N;char ch;
    cin>>N>>ch;
    int a=N,b=N-2;
    while(a--) cout<<ch;cout<<endl;
    if(N%2==0) a=N/2-2; else a=N/2-1;/**四舍五入取整*/
    while(a--){
        b=N-2;
        cout<<ch;
        while(b--) cout<<" ";
        cout<<ch<<endl;
    }
    a=N;
    while(a--) cout<<ch;cout<<endl;
    system("pause");
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/littlepage/p/11292268.html