ltx_zero

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

《算法笔记》3.3小节——入门模拟->图形输出

B无难度

注意一下最后一排,有两个数是被重复计算进去的,然后最后U下方处的len是n1+n2-1,对应数是str[n1+n2-2]

#include<stdio.h>
#include<string.h>
#include<string>
using namespace std;
int main()
{
    int n;
    char str[10000];
    while(scanf("%s",str)!=EOF)
    {
        n=strlen(str);
        int n1=(n+2)/3;
        int n2=n+2-2*n1;
        for(int i=0;i<n1-1;i++)
        {
            printf("%c",str[i]);
            for(int i=1;i<=n2-2;i++)
                printf(" ");
            printf("%c\n",str[n-1-i]);
        }
        for(int i=n1-1;i<n1+n2-1;i++)
            printf("%c",str[i]);
    }
    return 0;
}
View Code

 

posted on 2019-08-14 21:21  ltx_zero  阅读(76)  评论(0编辑  收藏  举报