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. yii 1.1简单文件缓存

    缓存组件配置在config\main.php文件,简单配置下文件缓存 'components'=>array( 'cache' => array( 'class' => 'syste ...

  2. pwd命令学习

    pwd命令学习 1.学习pwd命令 pwd命令功能为输出当前所在工作目录的绝对路径名称. 绝对路径和相对路径: 绝对路径:从根目录开始直到文件位置 相对路径:相对于程序当前所在目录到文件位置 例:程序 ...

  3. C# 使用 MsieJavaScriptEngine 引擎运行JavaScript

    用这个东西实现了一个js脚本引擎代码生成器,调研的时候这个东西的资料比较少. 我就根据自己的这点应用来讲解讲解,有错误,不符的地方还请园友指出. 使用 Nuget 安装 MsieJavaScriptE ...

  4. 二、Jmter查看结果数只能显示有限的数据,查看全部数据

    1.打开jmeter安装目录,找到bin目录下jmeter.properties文件 2.搜索:view.results.tree.max_size=10485760 3.将#号去掉,重启jmeter

  5. Bader分析

    一.背景 理查德·贝德(Richard Bader)开发了一种将分子分解为原子的直观方法.他对原子的定义纯粹基于电子电荷密度.Bader使用所谓的零磁通表面来划分原子.零通量表面是2D表面,其上电荷密 ...

  6. c++实验7 二叉树

    二叉树数据结构表示及基本操作算法实现 1.所加载的库函数或常量定义及类的定义: #include<stdlib.h> #include<stdio.h> #include&qu ...

  7. Linux_系统时间管理

    目录 目录 时间管理 date指令 系统时间设置timedatectl指令 本地时间同步 时间服务器NTP RHEL6 RHEL7 计划任务 一次性计划任务 at指令 限制用户建立一次性计划任务 周期 ...

  8. 阶段3 1.Mybatis_09.Mybatis的多表操作_5 完成user的一对多查询操作

    定义List<Account> accounts,生成getter和setter 复制AccountTest类改名UserTest类 修改测试类 还没封装所以Account的list都是n ...

  9. UnityEventSystem

    能够处理各种UI事件: IPointerEnterHandler:当指针进入 void OnPointerEnter(PointerEventData eventData); IPointerExit ...

  10. 2018.03.29 python-matplotlib 图表生成

    '''Matplotlib -> 一个python版的matlab绘图接口,以2D为主,支持python,numpy,pandas基本数据结构,高效图标库''' import numpy as ...