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 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 would 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 } 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 l
lowor
#include <iostream>
using namespace std;
int main()
{
/**读题
n1,n2,n3
n1=n3=height
n2=width
height=max(k|k<=width,3<=width<=N)
2*height+width-2=N
尽可能方形
*/
string s;
cin>>s;
int N=s.length(),width,height,left=,right=N-;
for(int i=;;i++){
if(*i->N){
height=i-;
width=N+-*height;
break;
}
}
for(int j=;j<height;j++){
if(j!=height-){
cout<<s[left];
for(int i=;i<width-;i++) cout<<" ";
cout<<s[right]<<endl;
left++;right--;
}else{
for(int i=left;i<=right;i++){
cout<<s[i];
}
}
}
system("pause");
return ;
}

PAT Advanced 1031 Hello World for U (20 分)的更多相关文章

  1. PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...

  2. PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...

  3. PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642 题目描述: Being unique is so important to peo ...

  4. PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642 题目描述: A reversible prime in any n ...

  5. PAT 甲级 1031 Hello World for U (20 分)(一开始没看懂题意)

    1031 Hello World for U (20 分)   Given any string of N (≥) characters, you are asked to form the char ...

  6. PAT (Advanced Level) Practice 1152 Google Recruitment (20 分)

    In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the p ...

  7. PAT Advanced 1058 A+B in Hogwarts (20 分)

    If you are a fan of Harry Potter, you would know the world of magic has its own currency system -- a ...

  8. PAT (Advanced Level) Practice 1120 Friend Numbers (20 分) (set)

    Two integers are called "friend numbers" if they share the same sum of their digits, and t ...

  9. PAT (Advanced Level) Practice 1015 Reversible Primes (20 分)

    A reversible prime in any number system is a prime whose "reverse" in that number system i ...

随机推荐

  1. C# 前台和后台POST提交信息的实现方法

    一.系统A(官网)与系统B(第三方支付平台)数据交换的方式 1.1  页面浏览器方式:系统A以构造Form表单的方式,通过系统A客户的浏览器重定向到系统B(向系统B发送请求),B系统完成交易后,将交易 ...

  2. ACM ICPC 2011-2012 Northeastern European Regional Contest(NEERC)K Kingdom Roadmap

    K: 给你n个点以及n-1的条边, 问你最少要加多少条边,使得每两个点割去一条联通的边,还可以使的这两个点连通. 有个一个结论,最少添加的边数为(叶子节点数+1)/ 2. 我们可以只考虑叶子节点数应该 ...

  3. linux命令--truncate 学习

    truncate命令可以将一个文件缩小或者扩展到某个给定的大小 可以利用该命令和-s选项来特别指定文件的大小 1.清空一个文件内容,尤其是log 2. truncate -s 0 test

  4. 转 HTTP请求报文格式 GET和POST

    https://blog.csdn.net/h517604180/article/details/79802914 最近在做安卓客户端图片上传插件功能,供后台调用.其中涉及到了拼接HTTP请求报文,所 ...

  5. SpEL 实例

    SpEl 实例 基于 Spring 解析 @RestController @RequestMapping("/spel") @Slf4j public class SpELCont ...

  6. pandas库简介和数据结构

    pandas简介 pandas是一个强大的Python数据分析的工具包.是基于Numpy来构件的. pandas提供快速.灵活和富有表现力的数据结构. 主要功能: 具备对其功能的数据结构DataFra ...

  7. 看看 Delphi XE2 为 VCL 提供的 14 种样式

    看看 Delphi XE2 为 VCL 提供的 14 种样式 其实只提供了 13 个 vsf 样式文件, 还有默认的 Windows 样式, 共 14 种. 在空白窗体上添加 ListBox1 等控件 ...

  8. C#简单工厂模式和单列设计模式潜要解析

    简单工厂设计模式,又叫做静态工厂方法(Static Factory Method)模式,就是由一个工厂类根据传入的参量决定创建出哪一种产品类的实例. 简单工厂模式是工厂模式家族中最简单实用的模式.简单 ...

  9. 【MM系列】SAP 客户增强

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP 客户增强   前言部分 大家 ...

  10. [Web 前端] 029 jQuery 元素的“节操”

    目录 jQuery 元素的节点操作 1. 创建节点 2. 插入节点 2.1 在现存元素的内部,从后面插入元素 2.2 在现存元素的内部,从前面插入元素 2.3 在现存元素的外部,从后面插入元素 2.4 ...