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 n1characters, 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≤n2≤N } 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
分析:图形输出题,意思是输出一个U的形状,不难发现规律,n1=n3=(N+2)/3向下取整,而n2=N+2-n1-n3,代码如下
/**
* Copyright(c)
* All rights reserved.
* Author : Mered1th
* Date : 2019-02-23-23.40.16
* Description : A1031
*/
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<unordered_set>
#include<map>
#include<vector>
#include<set>
using namespace std;
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif
string str;
cin>>str;
int len=str.length();
int n1,n2,n3;
n1=(len+)/;
n3=n1;
n2=len+-n1-n3;
int i;
;i<n1-;i++){
printf("%c",str[i]);
;j<n2-;j++){
printf(" ");
}
printf(]);
}
;i<n2;i++){
printf(]);
}
;
}
1031 Hello World for U (20 分)的更多相关文章
- 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 1031 Hello World for U (20 分) 凌宸1642
PAT (Advanced Level) Practice 1031 Hello World for U (20 分) 凌宸1642 题目描述: Given any string of N (≥5) ...
- 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 ...
- 【PAT甲级】1031 Hello World for U (20 分)
题意: 输入一个字符串长度为5~80,以'U'型输出,使得底端一行字符数量不小于侧面一列,左右两列长度相等. trick: 不把输出的数组全部赋值为空格为全部答案错误,可能不赋值数组里值为0,赋值后是 ...
- 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 ...
- 抛弃EF,20分构建一个属于自己的ORM框架
Poiuyt_cyc 博客园首页新随笔联系订阅管理随笔 - 11 文章 - 0 评论 - 111 抛弃EF,20分构建一个属于自己的ORM框架 相信EF大家都不陌生了,因为数据库表跟程序实体是一一 ...
- PTA 邻接表存储图的广度优先遍历(20 分)
6-2 邻接表存储图的广度优先遍历(20 分) 试实现邻接表存储图的广度优先遍历. 函数接口定义: void BFS ( LGraph Graph, Vertex S, void (*Visit)(V ...
- #020PAT 没整明白的题L1-009 N个数求和 (20 分)
后面的测试点过不去,两个错误一个超时. 目前未解决 L1-009 N个数求和 (20 分) 本题的要求很简单,就是求N个数字的和.麻烦的是,这些数字是以有理数分子/分母的形式给出的,你输出的和 ...
- L1-023 输出GPLT (20 分)
L1-023 输出GPLT (20 分) 给定一个长度不超过10000的.仅由英文字母构成的字符串.请将字符重新调整顺序,按GPLTGPLT....这样的顺序输出,并忽略其它字符.当然,四种字符(不区 ...
随机推荐
- ESET Smart Security 6 – 免费60天(SG)
ESS 60天 - 活动消息来自新加坡脸谱https://www.facebook.com/esetsingapore/app_190322544333196IP限制Sg,suiss提供个在线代理ht ...
- Java实现交换两个String
在Java中我们所使用的实例变量其实都是一个引用,所以如果要求实现一个swap(String A, String B)这种函数时无法实现的,因为在类方法的定义中是先对行参进行地址传递,然后对形参修改, ...
- 对抗网络之目标检测应用:A-Fast-RCNN
对抗网络之目标检测应用:A-Fast-RCNN 论文:A-Fast-RCNN: Hard Positive Generation via Adversary for Object Detection ...
- Excel 设置标题栏
1. 选中列表标题行, 可以设置字体居中显示,并放大字体以表示这是标题栏. 2. 选中列表第一数据行,即列表标题行下一行,选择View > Freeze Panes.
- file.replace
一.简介 salt file.replace 文件内容处理函数,类似于ansible的lineinfile模块 二.参数介绍 name 被编辑文件的绝对路径,支持软链接 pattern 常规表达式,使 ...
- C++ 写的地图控件,支持google 百度 在线离线地图
C++处理google 百度地图在网上查阅了很多都是通过浏览器方式显示地图信息, 跟我目前项目很不符合, 所以仔细研究了一下C++方式显示地图.通过地图投影以及墨卡托投影,在通过平面地图计算经纬度. ...
- liunx系统和其它的基本命令
1.su 更换用户 2.sudo 管理员权限 3.PATH 4.sudo shutdown -h now 现在关机 sudo shutdown -r now 现在重启 5.kill ...
- Spring DI
一. Spring DI 依赖注入 利用spring IOC实例化了对象,而DI将实例化的对象注入到需要对象的地方,完成初始化任务. 对象由spring创建,之后再由spring给属性赋值 spr ...
- HPU 1166: 阶乘问题(一)
1166: 阶乘问题(一) [数学] 时间限制: 1 Sec 内存限制: 128 MB提交: 58 解决: 24 统计 题目描述 小H对阶乘!很感兴趣.现在他想知道N!N!的位数,由于NN太大了,所以 ...
- SUST OJ 1671: 数字拼图
1671: 数字拼图 时间限制: 1 Sec 内存限制: 16 MB提交: 34 解决: 19[提交][状态][讨论版] 题目描述 拼图游戏即在任意一个N*N(N>1)的拼图中,会把一张完整 ...