Given any string of N (≥5) characters, you are asked to form the characters into the shape of U. For example, helloworld can be printed as:
1 2 3 4
h d e l l r lowo
That is, the characters must be printed in the original order, starting top-down from the left vertical line with n1 characters, then left to right along the bottom line with $n_2$ characters, and finally bottom-up along the vertical line with $n_3$ characters. And more, we would like U to be as squared as possible – that is, it must be satisfied that $n_1$=$n_3$=max { k | k≤$n_2$ for all 3≤$n_2$≤N } with $n_1$+$n_2$+$n_3$−2=N.
Input Specification:
Each input file contains one test case. Each case contains one string with no less than 5 and no more than 80 characters in a line. The string contains no white space.
output Specification:
For each test case, print the input string in the shape of U as specified in the description.
#include<cstdio> #include<cstring> char str[100]; intmain(){ freopen("A1031.txt","r",stdin); scanf("%s",str); int len = strlen(str)+2; int n1 = len/3; int n2 = len/3+len%3; len-=2; int idx = 0; for (int i = 0; i < n1-1; ++i) { printf("%c",str[idx]); for (int i = 1; i < n2-1; ++i) { printf(" "); } printf("%c\n",str[len-1-idx]); idx++; } for (int i = 0; i < n2; ++i) { printf("%c",str[idx++]); } printf("\n"); return0; }