U用A1031のHello World(20分|文字列処理、詳細に注釈を付け、ロジック解析)

免責事項:この記事はブロガーオリジナル記事です、続くBY-SAのCC 4.0を著作権契約、複製、元のソースのリンクと、この文を添付してください。
このリンク: https://blog.csdn.net/qq_24452475/article/details/100569617

EDITORIAL

  • アイデア解析
    • ここに画像を挿入説明
    • 10分問題、繰り返されることはありません(水タイトル)

テストケース

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

ACコード

  • ダイレクト出力
    #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;
    }
    
  • 参照コード

おすすめ

転載: blog.csdn.net/qq_24452475/article/details/100569617