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 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≤n​2​​≤N } 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

题目大意:给出一个字符串,要求按U型输出n1,n3分别是左边和右边从第一个到最后一个的高度,n2是底层的长度,要求满足n1=n3(k|k<=n2),也就是列的高度要小于等于底部的长度。

//猛一看这个题目还挺难的,我的AC:

#include <iostream>
#include <vector>
#include<cstdio>
using namespace std; int main() {
string s;
cin>>s;
int size=s.size();
int n13,n2;
n13=size/;
n2=n13+size%;
if(n13==n2){//如果两者相等的话,那么需要进行修改。
n13-=;
n2=size-n13*;
} for(int i=;i<size;i++){
if(i<n13){
cout<<s[i];
for(int j=;j<n2-;j++){
cout<<' ';
}
cout<<s[size--i]<<'\n';
}else{
break;
} }
//打印n2层
for(int i=n13;i<size-n13;i++){
cout<<s[i];
}
return ;
}

1.第一次提交时没通过,因为是如果是n13和n2相等的话,中间的空格就没办法输出了,所以就又添加了一个if判断是否相等,如果相等的话,那么就进行修改,便通过了。

PAT 1031 Hello World for U[一般]的更多相关文章

  1. 浙大pat 1031题解

    1031. Hello World for U (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Giv ...

  2. PAT 1031 Hello World for U

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

  3. PAT 1031 查验身份证(15)(C++&Python)

    1031 查验身份证(15)(15 分) 一个合法的身份证号码由17位地区.日期编号和顺序编号加1位校验码组成.校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5,8, ...

  4. PAT——1031. 查验身份证

    一个合法的身份证号码由17位地区.日期编号和顺序编号加1位校验码组成.校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8, ...

  5. PAT 1031. 查验身份证(15)

    一个合法的身份证号码由17位地区.日期编号和顺序编号加1位校验码组成.校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8, ...

  6. PAT 1031 查验身份证

    https://pintia.cn/problem-sets/994805260223102976/problems/994805290334011392 一个合法的身份证号码由17位地区.日期编号和 ...

  7. 1031. Hello World for U (20) PAT

    题目:http://pat.zju.edu.cn/contests/pat-a-practise/1031 分析: 简单题,调整数组的输出次序就可以了. 输入数组长度为len.n1 = n3 = (l ...

  8. PAT (Basic Level) Practise (中文)-1031. 查验身份证(15)

    PAT (Basic Level) Practise (中文)-1031. 查验身份证(15) http://www.patest.cn/contests/pat-b-practise/1031 一个 ...

  9. PAT乙级1031

    题目链接 https://pintia.cn/problem-sets/994805260223102976/problems/994805290334011392 题解 emmm.对于每个身份证号, ...

随机推荐

  1. Spring----Spring Boot Rest的使用方法

    1.下载Google浏览器并安装插件 转载: http://chromecj.com/web-development/2015-03/401/download.html 打开Google浏览器-> ...

  2. 如何连接 MySQL

    操作如下: [root@localhost ~]$ mysql -uroot -p' # 本地连接 MySQL 服务 [root@localhost ~]$ mysql -uroot -p' -h19 ...

  3. 如何设置SOLR的高亮 (highlight)?

    打开SOLR的核心配置文件: solrconfig.xml 找到 standard request handler 写入以下XML配置代码: <requestHandler name=" ...

  4. On iPad, UIImagePickerController must be presented via UIPopoverController

    本文转载至:http://blog.csdn.net/k12104/article/details/8537695 On iPad, UIImagePickerController must be p ...

  5. ubuntu 安装nfs 服务

    1. 安装nfs服务软件 (1)服务器端 $sudo apt-get install nfs-kernel-server  rpcbind (2)客户端 (可以省略) $sudo apt-get in ...

  6. Android 7.1 SystemUI--Multi-Window多窗口模式

    PhoneStatusBar.java private View.OnLongClickListener mRecentsLongClickListener = new View.OnLongClic ...

  7. SenchaTouch调用纯数字键盘

    items:[ { itemId:"phoneNumber", xtype: "textfield", component:{xtype:"input ...

  8. video事件

    /** video播放器*/ * @ src: 指定所要嵌入视频.文档的URL. * @ poster: 视频预览图像 * @ autoplay: 视频自动播放 * @ loop: 循环播放 * @ ...

  9. java中生成流水号的一个例子(使用关系型数据库)

    在实际的开发中,可能会有根据一定的规则生成流水号的需求(比如根据根据公司编码和日期生成4位流水号)我们可以把公司和日期联合起来作为一个业务编码,把这个业务编码和序列的值存储到数据库中,每次需要生成流水 ...

  10. ShowDoc 搭建 (未成功....)

    官方教程:https://www.showdoc.cc/help?page_id=13732 下载了showdoc,服务器映射本地磁盘的时候,服务器用户名和密码忘了... 远程服务器用户名和密码修改 ...