A1031 Hello World for U (20 minutes | string processing, annotated in detail, logic analysis)

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_24452475/article/details/100569617

EDITORIAL

  • Ideas analysis
    • Here Insert Picture Description
    • 10 minutes a problem, will not be repeated (water title)

Test Case

  • input:
    helloworld!
    
    output:
    h   !
    e   d
    l   l
    lowor
    

ac Code

  • Direct output
    #include<iostream>
    #include<string>
    using namespace std;
    int main()
    {
        string s;
        cin >> s;
        int len = s.length(), lrhigh = (len+2) / 3, bottom = len - 2 * lrhigh;
        for (int i = 0; i < lrhigh-1; i++)
        {
            printf("%c", s[i]);
            for (int k = bottom; k >0; k--)printf(" ");
            printf("%c", s[len - 1 - i]);
            printf("\n");
        }
        for (int i = lrhigh - 1; i <= lrhigh + bottom; i++)
            printf("%c", s[i]);
        return 0;
    }
    
  • Reference Code

Guess you like

Origin blog.csdn.net/qq_24452475/article/details/100569617