PTA (Basic Level) 1036. Programmed together with Obama

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≤ N ≦ 20) 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
Thinking
  • In the print image topic, this question is considered a very water, and the relationship between characters and spaces are evident
Code
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    char c;
    cin >> n >> c;
    for(int i=0;i<n;i++)    cout << c;
    cout << endl;

    for(int i=0;i<round(0.5 * n) - 2;i++)
    {
        cout << c;
        for(int j=0;j<n-2;j++)  cout << " ";
        cout << c;
        cout << endl;
    }

    for(int i=0;i<n;i++)    cout << c;
    return 0;
}

Quote

https://pintia.cn/problem-sets/994805260223102976/problems/994805285812551680

Guess you like

Origin www.cnblogs.com/MartinLwx/p/11665118.html