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

#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;
}
网友评论