A1031 Hello World for U (20 分| 字符串处理,附详细注释,逻辑分析)

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_24452475/article/details/100569617

写在前面

  • 思路分析
    • 在这里插入图片描述
    • 10分钟a题,不再赘述(水题)

测试用例

  • 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
今日推荐