1031. Hello World for U (limited) time MS
Memory Limit 32000 KB
Code length limit 16000 B
Standard author CHEN, Yue
Given any string of N (>=5) characters, and you are asked to form the characters into the shape of U. For example, the "HelloWorld" can be printed as:
H d
e l
l R
Lowo
This is, the characters must are printed in the original order, starting Top-down to the left vertical line with n 1chara Cters, 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 you to being as squared as possible--that's, it must being 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 is contains one string with no less than 5 and no more than-characters in a line. The string contains no white spaces.
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 L
lowor
The key is to find out N1 and N2, the largest number of data in 80, so N1 and N2 when the direct violence to solve can be.
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main () {
int a,amax,b,k,len,i,j;
Char str[100];
scanf ("%s", str);
len = strlen (str);
Amax =-1;
for (b=3;b<=len;++b) {for
(a=1;a<=b;++a) {
if (2*a+b-2==len) {
if (a>amax) Amax = A;
Continue
}
}} A = Amax;
b = len+2-2*a;
for (i=0;i<a-1;++i) {
cout<<str[i];
for (j=0;j<b-2;++j) {
cout<< ';
}
cout<<str[len-i-1]<<endl;
}
Str[len-i]= ' ";
cout<<str+i<<endl;
return 0;
}