Pat 1031, Zhejiang. Hello World for U (20)

Source: Internet
Author: User

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;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.