跳到正文

题解

B3924 [GSEP202312 二级] 小杨的H字矩阵 tj

_colin1112_约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟
获赞
4
题目
B3924

版本

  1. v1当前

简单模拟,但 std 寄了()。

思路

输出 nn 行,每一行的最左边和最右边为 |,,中间当行数为 n+12\frac{n+1}{2} 时输出 -,其他都输出 a。

注意不能有多余空行和空格。

Code

C++
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'

using namespace std;
const int E = 1e6 + 5;
ll n;
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        if (i == (n + 1) / 2)
        {
            for (int j = 1; j <= n; j++)
            {
                if (j == 1 || j == n)
                    cout << "|";
                else
                    cout << "-";
            }
            if (i != n)
                cout << endl;
            continue;
        }
        for (int j = 1; j <= n; j++)
        {
            if (j == 1 || j == n)
                cout << "|";
            else
                cout << "a";
        }
        if (i != n)
            cout << endl;
    }
    return 0;
}
原文