A1031 Hello World for U

摘要
Title: A1031 Hello World for U
Tag: 模拟
Memory Limit: 64 MB
Time Limit: 1000 ms

Powered by:NEFU AB-IN

Link

A1031 Hello World for U

  • 题意

    也就是说,必须按照原始顺序输出字符,左垂直线自上而下共有 n1 个字符,底部行从左到右共有 n2 个字符,右垂直线自下而上共有 n3 个字符。
    另外,必须满足 n1=n3=max{k|k≤n2对于所有3≤n2≤N} 以及 n1+n2+n3−2=N。

  • 思路

    根据满足的等式和不等式,求出n1,n2,n3,之后输出即可

  • 代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    /*
    * @Author: NEFU AB-IN
    * @Date: 2023-01-07 19:35:12
    * @FilePath: \GPLT\A1031\A1031.cpp
    * @LastEditTime: 2023-01-07 19:41:49
    */
    #include <bits/stdc++.h>
    using namespace std;
    #define int long long
    #define SZ(X) ((int)(X).size())
    #define IOS \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr); \
    cout.tie(nullptr)
    #define DEBUG(X) cout << #X << ": " << X << '\n'
    typedef pair<int, int> PII;

    const int N = 1e5 + 10, INF = 0x3f3f3f3f;

    // #undef int

    signed main()
    {
    IOS;
    string s;
    cin >> s;

    int sz = SZ(s);
    int n1 = (sz + 2) / 3, n3 = (sz + 2) / 3, n2 = sz - n1 - n3 + 2;

    for (int i = 0; i < n1 - 1; ++i)
    {
    cout << s[i];
    for (int j = 0; j < n2 - 2; ++j)
    cout << " ";
    cout << s[sz - i - 1] << '\n';
    }
    int i = n1 - 1;
    while (true)
    {
    cout << s[i++];
    if (i == n1 + n2 - 1)
    break;
    }

    return 0;
    }
使用搜索:谷歌必应百度