【PAT甲级 图形输出】1031 Hello World for U (20 分)

#include<bits/stdc++.h>
using namespace std;

int n1, n2, n3, N;
string S;

int main() {
    
    
    cin >> S;
    N = S.size();
    n1 = n3 = (N+2)/3; // 重要的是找到n1的规律公式
    n2 = N+2 - n1 - n3;

    string S1 = S.substr(0, n1);
    string S2 = S.substr(n1-1, n2);
    string S3 = S.substr(n1+n2-2);

    for(int i = 0;i < S1.size()-1;++i) {
    
    
        cout << S1[i];
        for(int j = 0;j < S2.size()-2;++j)
            cout << " ";
        cout << S3[S3.size()-1-i];
        cout << endl;
    }
    cout << S2 << endl;

    return 0;
}

猜你喜欢

转载自blog.csdn.net/MYMarcoreus/article/details/114551707