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:
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 N
1 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 wowould 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.
Sample input:
Helloworld!
Sample output:
H!
E d
L
Lowor
// You can use the char array. I like to use string for simple operations. # include <iostream >#include <string> using namespace STD; int main () {string STR; int N, N1, N2, N3, I, j, start, end; while (CIN> Str) {n = Str. length (); n1 = N3 = (n + 2)/3; N2 = N-N1-N3 + 2; Start = 0; end = n-1; for (I = 0; I <N1; I ++) {if (I = N1-1) {for (j = 0; j <N2; j ++) {cout <STR [start ++] ;}} else {cout <STR [start ++]; for (j = 0; j <n2-2; j ++) {cout <";} cout <STR [end --] <Endl ;}} return 0 ;}
1031. Hello world for U (20)