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....这样的顺序输出,并忽略其它字符.当然,四种字符(不区 ...
随机推荐
- C++语言的一些问题
论坛上看到的有人提出的关于C++的一些问题,真是细致(下面还有回复说他对C++一知半解的),一直以为自己的C++还是可以的,可是看了之后真是内牛满面,为什么自己从来没有想的这么深入,差距真的有这么大吗 ...
- IDC:2014年的十大 IT 趋势
IDC:2014年的十大 IT 趋势 市场研究公司 IDC 近日发布报告,对 2014 年的十大科技行业发展趋势作出了预测.IDC 称,2014 年将是科技业"鏖战正酣"的一年,整 ...
- android短彩信附件机制
将一些认识写下来,和大家交流一下,同时也方便自己复习. 用户可以通过附件按钮,添加附件.以添加幻灯片为例: 如果点击幻灯片,会走如下代码: ComposeMessageActivity.java pr ...
- jQuery 3.1 参考手册.CHM离线版下载
制作了一份jQuery 3.1 参考手册.CHM离线版供大家使用 点击下载 预览一下
- postman--安装及Interceptor插件
1. 官网安装(看网速-我下载的时候一直下载失败) 打开官网,https://www.getpostman.com 选择ios或者win 2. 非官网安装 https://pan.baidu. ...
- convert CAN frame
前言 最近了解了一些socket can的知识点,本文主要介绍如何将数据转换为CAN报文,前提是已经确定CAN的传输协议. 本文使用的CAN报文共有22条,这些报文共用一个can id,每条报文使用序 ...
- requests中获取请求到文本编码格式
1.使用requests模块: import requests 2.通过网络请求,并获取到数据 url = "http://www.stat-nba.com/award/item14.htm ...
- Microsoft - Union Two Sorted List with Distinct Value
Union Two Sorted List with Distinct Value Given X = { 10, 12, 16, 20 } & Y = {12, 18, 20, 22} W ...
- MySQL账号安全设置
======================================================================== 推荐账号安全设置 在数据库服务器上严格控制操作系统的账 ...
- day25 python学习 继承,钻石继承
通过一个列子认识父类和子类中,子类的如何实现对父类默认属性调用,同时拥有自己的属性,如何在子类中调用父类的方法,class Ainmal: country='afdas' def __init__(s ...