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

题意

一开始没看懂题意,看懂以后一遍过。

尽可能围成正方形。在满足n1=n3,且n1<=n2的条件下,n1尽可能地大。

底部字符数量 n2 最少为3。n1 = n3 要尽量等于 n2 。也就是说,n1 = n3 = (n+2) / 3;因为 '/ 3' 会截掉小数部分,所以 n1 和 n3 总是小于或者等于 n2 。

AC代码:

#include<bits/stdc++.h>
using namespace std;
char a[];
int main(){
cin>>a;
int l=strlen(a);
int n1=(l+)/;
int n2=l-n1*;
//cout<<n1<<" "<<n2<<endl;
for(int i=;i<n1-;i++){
cout<<a[i];
for(int j=;j<=n2;j++){
cout<<" ";
}
cout<<a[l--i]<<endl;
}
for(int i=n1-;i<=n1+n2;i++){
cout<<a[i];
}
return ;
}

PAT 甲级 1031 Hello World for U (20 分)(一开始没看懂题意)的更多相关文章

  1. PAT甲级:1136 A Delayed Palindrome (20分)

    PAT甲级:1136 A Delayed Palindrome (20分) 题干 Look-and-say sequence is a sequence of integers as the foll ...

  2. PAT 甲级 1054 The Dominant Color (20 分)

    1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ab ...

  3. PAT 甲级 1027 Colors in Mars (20 分)

    1027 Colors in Mars (20 分) People in Mars represent the colors in their computers in a similar way a ...

  4. PAT 甲级 1005 Spell It Right (20 分)

    1005 Spell It Right (20 分) Given a non-negative integer N, your task is to compute the sum of all th ...

  5. PAT 甲级 1058 A+B in Hogwarts (20 分) (简单题)

    1058 A+B in Hogwarts (20 分)   If you are a fan of Harry Potter, you would know the world of magic ha ...

  6. PAT 甲级 1023 Have Fun with Numbers (20 分)(permutation是全排列题目没读懂)

    1023 Have Fun with Numbers (20 分)   Notice that the number 123456789 is a 9-digit number consisting ...

  7. 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 ...

  8. 【PAT甲级】1054 The Dominant Color (20 分)

    题意: 输入两个正整数M和N(M<=800,N<=600),分别代表一张图片的宽度和高度,接着输入N行每行包括M个点的颜色编号,输出这张图片主导色的编号.(一张图片的主导色占据了一半以上的 ...

  9. 【PAT甲级】1001 A+B Format (20 分)

    题意:给两个整数a,b,计算a+b的值并每三位用逗号隔开输出(−1e6​​≤a,b≤1e6​​) AAAAAccepted code: #include<bits/stdc++.h> us ...

随机推荐

  1. 【PAT-并查集-水题】L2-007-家庭房产

    L2-007. 家庭房产 给定每个人的家庭成员和其自己名下的房产,请你统计出每个家庭的人口数.人均房产面积及房产套数. 输入格式: 输入第一行给出一个正整数N(<=1000),随后N行,每行按下 ...

  2. 新闻系统——VS制作自己的模板

    我们在做机房管理的项目时,就用过模板方法,建立一个模板,这样就会省很多事,我们不需要每次都添加同样的东西,比如我们的类窗体,就可以制作一个模板,将注释和需要引用的控件直接添加上,这可以省去很大的麻烦, ...

  3. matlab(4) Logistic regression:求θ的值使用fminunc / 画decision boundary(直线)plotDecisionBoundary

    画decision boundary(直线) %% ============= Part 3: Optimizing using fminunc =============% In this exer ...

  4. idea中关闭当前文件快捷键

    一.idea中关闭当前文件快捷键 1.一般编辑器中关闭当前文件快捷键为ctrl+w 2.而idea中默认为Ctrl+F4 3.可以将其改为自己熟悉的键位. 4.settings——>keymap ...

  5. java技术哪些是必学的?

    福州seo推广我们接触过java需要的小伙伴们都知道java是一门强大而又复杂的编程语言,现如今在互联网行业,java的身影随处可见,可能刚学习的小伙伴们会被java语言庞大的体系图吓到,不过知识毕竟 ...

  6. Linux OOM killer 与相关参数详解

    一.前言 本文是描述Linux virtual memory运行参数的第二篇,主要是讲OOM相关的参数的.为了理解OOM参数,第二章简单的描述什么是OOM.如果这个名词对你毫无压力,你可以直接进入第三 ...

  7. Linux 文件系统缓存dirty_ratio与dirty_background_ratio两个参数区别

    文件系统缓存dirty_ratio与dirty_background_ratio两个参数区别 (2014-03-16 17:54:32) 转载▼ 标签: linux 文件系统缓存 cache dirt ...

  8. 发布新的模型类包(用于上传到 NuGet 服务器上)

    生成包文件: 1.修改了模型类之后,在项目上点击右键,在列表菜单中选择 “编辑 …….csproj”,然后将里面的三个版本号都换成新的版本号. 2.右键项目,点击“打包” 3.复制输出信息中生成的包的 ...

  9. 容器网络启用RDMA高速通讯-Freeflow

    容器网络启用RDMA高速通讯-Freeflow 容器网络启用RDMA高速通讯-Freeflow 本文编译自: Freeflow,https://github.com/openthings/Freefl ...

  10. nginx + keepalived双活配置

    一.安装nginx 我们这边默认安装的nginx的是1.12.2的版本,所以我们需要安装1.16.1版本的nginx的,才好,所以我们这边先更新yum源,步骤如下: 1.添加yum源: [root@s ...