输入:
There are multiple test cases. Each case contains one string with no less than 5 and no more than 100 characters in a line. The string maybe contains one or more white spaces.
输出:
For each test case, print the input string in the shape of U as specified in the description.
例:
输入:
helloworld!
hello world
输出:
h !
e d
l l
lowor
h d
e l
l r
lo wo
解决代码如下:
# include <stdio.h>
# include <string.h>
void print_u(char *str);
int main(){
char str[1000];
while(gets(str)){
if(strcmp(str, "") == 0) break;
print_u(str);
}
return 0;
}
void print_u(char *str){
char result[1000];
int len = strlen(str), n1, n2;
n1 =(len+ 2) / 3;
n2=n1+(len + 2) % 3;
char *i= str, *j= str + len - 1;
for(int k=1; k < n1; k++){
printf("%c", *i);
for(int t = 0; t < n2 - 2; t++) printf(" ");
printf("%c\n", *j);
i++;
j--;
}
*(j + 1) ='\0' ;
strcpy(result, i);
puts(result);
}