1031. Hello World for U

标签: pat
30人阅读 评论(0) 收藏 举报
分类:

1031. Hello World for U (20)

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:

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 n2 characters, and finally bottom-up along the vertical line with n3 characters. And more, we would like U to be as squared as possible -- that is, it must be satisfied that n1 = n3 = max { k| k <= n2 for all 3 <= n2 <= N } with n1 + n2 + n3 - 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   l
lowor

1. n1<=n2

2. n1=n3

3. 在这个前提下,n1尽可能大(图形要尽可能正方be as squared as possible)

#include<iostream>
#include<string>
using namespace std;
string an;
int main()
{
	int len,n1,n2,sp;
	cin >> an;
	string::iterator ib=an.begin();
	string::iterator ie=an.end();
	len=an.size();
	n1=(len+2)/3;
	n2=len+2-2*n1;
	sp=n2-2;
	for(int i=1;i<=n1;i++)
	{
		if(i!=n1)
		{
			cout << *ib;
			for(int j=0;j<sp;j++)
				cout << ' ';
			cout << *(ie-1) << endl;
			ib++,ie--;
		}
		else
		{
			for(;ib!=ie;ib++)
				cout << *ib;
		}
	}
	return 0;
} 


查看评论

浙大PAT 1031. Hello World for U (20)

1031. Hello World for U (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 1600...
  • IAccepted
  • IAccepted
  • 2014-03-03 16:35:03
  • 1897

1031. Hello World for U (20)-PAT甲级真题

1031. Hello World for U (20) Given any string of N (>=5) characters, you are asked to form the ...
  • liuchuo
  • liuchuo
  • 2016-08-04 15:43:54
  • 191

PAT-PAT (Advanced Level) Practise 1031. Hello World for U (20) (图形打印) 【二星级】

题目链接:http://www.patest.cn/contests/pat-a-practise/1031 题面: 1031. Hello World for U (20) ...
  • David_Jett
  • David_Jett
  • 2015-08-20 09:19:57
  • 682

PAT甲级1031

1031. Hello World for U (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 1600...
  • qq_22194315
  • qq_22194315
  • 2017-01-09 17:09:29
  • 183

pat1031Hello World for U (20)

题意分析: (1)给出一个长度大于5的字符串,然后从上到下输出n1个字符,从左到右到右输出n2个字符(包括边界,也就是n1的最后一个字符),从下到上输出n3个字符,让结果尽可能呈现方形,按照题目中公式...
  • LostStephon
  • LostStephon
  • 2015-10-04 22:50:25
  • 262

1031. Hello World for U 解析

注意端点值,不然有的示例不能过。 #include #include using namespace std; int main() { string s; cin >> s; ...
  • sheepyWYY
  • sheepyWYY
  • 2017-02-07 22:48:33
  • 72

PAT-A 1031. Hello World for U

Given any string of N (>=5) characters, you are asked to form the characters into the shape of U. Fo...
  • ww1473345713
  • ww1473345713
  • 2016-07-31 23:17:00
  • 75

1031. Hello World for U (20)

Given any string of N (>=5) characters, you are asked to form the characters into the shape of U. Fo...
  • zjujqq
  • zjujqq
  • 2013-08-29 16:00:54
  • 496

【PAT】1031. Hello World for U

#include #include #include #include #include using namespace std; char str[82]; int main(){ ...
  • KID_LWC
  • KID_LWC
  • 2017-01-17 22:01:20
  • 89

汇编语言 写 Hello World

汇编语言 写 Hello World博主菜鸟一枚,纯属个人摸索,不喜勿喷。t_t 1.DOS,是 磁盘操作系统 的缩写,是个人计算机上的一类操作系统。 2.汇编语言运行在基于DOS操作系统的环...
  • xu_san_duo
  • xu_san_duo
  • 2016-12-28 18:41:35
  • 575
    个人资料
    持之以恒
    等级:
    访问量: 4万+
    积分: 4427
    排名: 8454