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 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 } 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
#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 分)的更多相关文章
- PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642
PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...
- PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642
PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...
- 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 ...
- PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642
PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642 题目描述: A reversible prime in any n ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 搜索引擎算法研究专题七:Hilltop算法
搜索引擎算法研究专题七:Hilltop算法 2017年12月19日 ⁄ 搜索技术 ⁄ 共 1256字 ⁄ 字号 小 中 大 ⁄ 评论关闭 HillTop也是搜索引擎结果排序的专利,是Google工 ...
- Mybaits配置多个数据库操作sql环境
mybitas可以配置sql语句适用于不同数据库下的操作,因为不同数据库sql语句可能有差别,接下来介绍如果进行操作 1.在jdbc.properprites配置驱动 jdbc.driver=com. ...
- Mac上的应用,例如Xcode需要输入原始下载账号才能更新问题
为了免下载安装Xcode,安装时使用了别人提供的Xcode.dmg安装,或者公司接管上任同事使用的Mac时,上面的应用都是用别人的账号购买下载的,而非使用自己账号在AppStore下载的. 这样的安装 ...
- promise不会被return触发, 一个promise对象中不会被Promise.reject触发
1. let a = new Promise((resolve,reject)=>{ return 23 }) a; // promise <pending> 2. let a = ...
- 阶段3 1.Mybatis_03.自定义Mybatis框架_7.自定义Mybatis的编码-实现基于注解配置的查询所有
注解的方式,这里进行修改.上面注释的是原来xml的方式. 在dao类里面加上注解 创建注解类 声明注解的生命周期为Runntime 改变注解出现的位置,在Mehtod方法上 写完之后这里就不报错了. ...
- c# AES128 加解密算法
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- JavaScript基础之--- 深拷贝与浅拷贝
理解深拷贝和浅拷贝之前,先来看一下JavaScript的数据类型. 1.基本类型和引用类型 //案例1 var num1 = 1, num2 = num1; console.log(num1) con ...
- RabbitMQ使用(下)
RabbitMQ从信息接收者角度可以看做三种模式,一对一,一对多(此一对多并不是发布订阅,而是每条信息只有一个接收者)和发布订阅.其中一对一是简单队列模式,一对多是Worker模式,而发布订阅包括发布 ...
- 在linux服务器上自动备份数据库
脚本如下,没有任何问题: # !/usr/bin/pythonimport osimport timeimport datetimeimport pipesimport glob DB_HOST = ...
- 2.nginx配置详细说明
Nginx配置详解 nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP服务器进行 ...