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=(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 分)的更多相关文章

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

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

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

  4. 【PAT甲级】1031 Hello World for U (20 分)

    题意: 输入一个字符串长度为5~80,以'U'型输出,使得底端一行字符数量不小于侧面一列,左右两列长度相等. trick: 不把输出的数组全部赋值为空格为全部答案错误,可能不赋值数组里值为0,赋值后是 ...

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

  6. 抛弃EF,20分构建一个属于自己的ORM框架

    Poiuyt_cyc 博客园首页新随笔联系订阅管理随笔 - 11  文章 - 0  评论 - 111 抛弃EF,20分构建一个属于自己的ORM框架 相信EF大家都不陌生了,因为数据库表跟程序实体是一一 ...

  7. PTA 邻接表存储图的广度优先遍历(20 分)

    6-2 邻接表存储图的广度优先遍历(20 分) 试实现邻接表存储图的广度优先遍历. 函数接口定义: void BFS ( LGraph Graph, Vertex S, void (*Visit)(V ...

  8. #020PAT 没整明白的题L1-009 N个数求和 (20 分)

    后面的测试点过不去,两个错误一个超时. 目前未解决   L1-009 N个数求和 (20 分)   本题的要求很简单,就是求N个数字的和.麻烦的是,这些数字是以有理数分子/分母的形式给出的,你输出的和 ...

  9. L1-023 输出GPLT (20 分)

    L1-023 输出GPLT (20 分) 给定一个长度不超过10000的.仅由英文字母构成的字符串.请将字符重新调整顺序,按GPLTGPLT....这样的顺序输出,并忽略其它字符.当然,四种字符(不区 ...

随机推荐

  1. 2018-2019-2 网络对抗技术 20165202 Exp5 MSF基础应用

    博客目录 一.实践目标 二.实践内容 一个主动攻击实践,ms08_067(成功).ms03_026(成功且唯一); 一个针对浏览器的攻击,如ms11_050(成功)ms11_03(失败.唯一)ms10 ...

  2. 给迷茫的你学习Node.js最好的方法

    这是真事儿,在3w咖啡整理书稿,然后小弟梁过来了,聊聊他的现状,一副很不好的样子,在天津我曾带过他大半年,总不能不管,我给他的建议是:“每天看10个npm模块” 对于学习Node.js迷茫的人来说,这 ...

  3. 2.1 Linux中wait、system 分析

    wait与waitpid: 当子进程退出的时候,内核会向父进程发送SIGCHID信号,子进程的退出是一个异步事件(子进程可以在父进程运行的任何时刻终止). 子进程退出时,内核将子进程置为僵尸状态,这个 ...

  4. Mac锁屏快捷键

    Mac 锁屏快捷键 直接盖 -- 推荐,因为帅 control + command + Q -- 真正意义上的锁屏.可行 control + shift + Power -- 只是黑屏,再次打开不需要 ...

  5. CF1143F/1142C U2

    CF1143F/1142C U2 巧妙的思维题.注意到这里只用两个点就可以确定一根抛物线,联想到两点确定一条直线,尝试转化. \(y=x^2+bx+c\) 就可以写成 \(y-x^2=bx+c\) , ...

  6. SQL SERVER 2008R2 执行大脚本文件时,管理工具提示“内存不足”的解决方法

    项目需求:当我把服务器上的数据库导出为SQL脚本时,在本地新建数据库,再导入执行SQL文件时报错,因为SQL文件过大,导致出现如下报错 如下图所示: ========================= ...

  7. (2)socket的基础使用(基于TCP协议)

    socket()模块函数用法 基于TCP协议的套接字程序 netstart -an | findstr 8080 #查看所有TCP和UDP协议的状态,用findstr进行过滤监听8080端口 服务端套 ...

  8. 杭电OJ1789、南阳OJ236(贪心法)解题报告

    杭电OJ1789http://acm.hdu.edu.cn/showproblem.php?pid=1789 南阳OJ236http://59.69.128.203/JudgeOnline/probl ...

  9. hdu1281 棋盘游戏 二分图最大匹配

    小希和Gardon在玩一个游戏:对一个N*M的棋盘,在格子里放尽量多的一些国际象棋里面的“车”,并且使得他们不能互相攻击,这当然很简单,但是Gardon限制了只有某些格子才可以放,小希还是很轻松的解决 ...

  10. 【spring源码分析】面向切面编程架构设计

    2 注解说明 2.1 @Aspect 作用是把当前类标识为一个切面供容器读取 2.2 @Before标识一个前置增强方法,相当于BeforeAdvice的功能,相似功能的还有 2.3 @AfterRe ...