美文网首页PTA甲级
1031 Hello World for U (20 分)

1031 Hello World for U (20 分)

作者: zilla | 来源:发表于2019-01-03 23:07 被阅读0次

虽然是道简单题,但是实现的这么省空间省时间一下子就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;
}

相关文章

  • PAT A1031 Hello World for U

    PAT A1031 Hello World for U A1031 Hello World for U 题目 如何...

  • 1031 Hello World for U (20 分)

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

  • PAT 1031:Hello World for U

    Given any string of N (>=5) characters, you are asked to ...

  • Hello World

    Hello World! This demo is written by Markdown Tips for u:...

  • PAT_1045 Hello World for U (20)

    题目描述: 给定任意N(> = 5)个字符的字符串,系统会要求您将字符组成U形。例如,“helloworld”可以...

  • 4 替换空格

    题目 把字符串中出现的空格替换为“%20”。示例“Hello World” 变为“Hello%20World" 结...

  • 常用markdown语法

    Hello World! Hello World! Hello World! Hello World! Hello...

  • hello

    hello, world hello, world hello, world hello, world

  • Markdown

    标题: hello world hello world hello world hello world hello...

  • 2018-06-11

    markdown hello world hello world hello world hello world ...

网友评论

    本文标题:1031 Hello World for U (20 分)

    本文链接:https://www.haomeiwen.com/subject/mxjcrqtx.html