1031. Hello World for U (20)

时间限制

400 ms

内存限制

65536 kB

代码长度限制

16000 B

判题程序

Standard

作者

CHEN, Yue

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 n1characters, 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

来源: <http://www.patest.cn/contests/pat-a-practise/1031>

  1. #pragma warning(disable:4996)
  2. #include <stdio.h>
  3. #include <string>
  4. #include <iostream>
  5. using namespace std;
  6. int main(void) {
  7. int n1, n2, n3;
  8. string s;
  9. cin >> s;
  10. n1 = n3 = (s.length() - 1) / 3;
  11. n1++; n3++;
  12. n2 = s.length() + 2 - 2 * n1;
  13. for (int i = 0; i < n1 - 1; i++) {
  14. cout << s[i];
  15. for (int i = 0; i < n2 - 2; i++)
  16. cout << ‘ ‘;
  17. cout << s[s.length() - i - 1] << endl;
  18. }
  19. for (int i = n1 - 1; i < n1 + n2-1; i++) {
  20. cout << s[i];
  21. }
  22. return 0;
  23. }

来自为知笔记(Wiz)

时间: 2024-12-30 04:03:06

1031. Hello World for U (20)的相关文章

1031 Hello World for U (20 分)

1031 Hello World for U (20 分) Given any string of N (≥) 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, s

1031 Hello World for U (20分)

Given any string of N (≥) 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

【PAT甲级】1031 Hello World for U (20 分)

题意: 输入一个字符串长度为5~80,以'U'型输出,使得底端一行字符数量不小于侧面一列,左右两列长度相等. trick: 不把输出的数组全部赋值为空格为全部答案错误,可能不赋值数组里值为0,赋值后是' ',空格的ascii是32,初读题面时并没有看到要输出空格,因为打印0其实效果看起来好像一样... 代码: #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;string s;char a[87][87

PAT Advanced 1031 Hello World for U (20分)

Given any string of N (≥) 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

pat1031. Hello World for U (20)

1031. Hello World for U (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue 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

1031. Hello World for U

1031. Hello World for U (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue 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

mahout安装测试

Mahout 是 Apache Software Foundation(ASF) 旗下的一个开源项目,提供一些可扩展的机器学习领域经典算法的实现,旨在帮助开发人员更加方便快捷地创建智能应用程序.Apache Mahout项目已经发展到了它的第三个年头,目前已经有了三个公共发行版本.Mahout包含许多实现,包括聚类.分类.推荐过滤.频繁子项挖掘.此外,通过使用 Apache Hadoop 库,Mahout 可以有效地扩展到云中. Mahout 的创始人 Grant Ingersoll 介绍了机器

A题目

1 1001 A+B Format(20) 2 1002 A+B for Polynomials(25) 3 1003 Emergency(25) 4 1004 Counting Leaves(30) 5 1005 Spell It Right(20) 6 1006 Sign In and Sign Out(25) 7 1007 Maximum Subsequence Sum(25) 8 1008 Elevator(20) 9 1009 Product of Polynomials(25) 10

kali linux 入侵window实例

我使用Kali Linux的IP地址是192.168.0.112:在同一局域网内有一台运行Windows XP(192.168.0.108)的测试电脑. 本文演示怎么使用Metasploit入侵windows xp sp3. 启动msfconsole: # msfconsole 选择一个漏洞: msf > search platform: windows xp sp3 exploit/windows/smb/ms08_067_netapi是08年发现的漏洞,等级Great. 查看某个漏洞的详细信