PTA甲级

1031 Hello World for U (20 分)

2019-01-03  本文已影响0人  zilla

虽然是道简单题,但是实现的这么省空间省时间一下子就ac还是有点爽


(笑)

题目链接 Advanced1031

#include <stdio.h>
#include <string.h>
int main() {
    char str[81];
    char spaces[40];
    scanf("%s",str);
    int len=strlen(str);
    int height=(len+2)/3-1;//index 0 - height-1
    int space_width=len-2*height-2;
    for(int i=0;i<space_width;i++)
        spaces[i]=' ';
    spaces[space_width]='\0';
    for (int j = 0; j < height; ++j) {
        printf("%c%s%c\n",str[j],spaces,str[len-j-1]);
    }
    str[len-height]='\0';
    printf("%s\n",str+height);
    return 0;
}
上一篇 下一篇

猜你喜欢

热点阅读