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型输出。

思路:

找到小于len+2的最大的三的倍数,(len+2)/3就是竖着的个数。

 #include <iostream>
#include <set>
#include <cmath>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef long long LL;
#define inf 0x7f7f7f7f char s[]; int main()
{
scanf("%s", s);
int n = strlen(s);
int x = (n + ) / ;
int y = n - * x; for(int i = ; i < x - ; i++){
printf("%c", s[i]);
for(int j = ; j < y; j++){
printf(" ");
}
printf("%c\n", s[n - - i]);
}
for(int i = x - ; i <= x + y; i++){
printf("%c", s[i]);
}
printf("\n"); return ;
}

PAT甲1031 Hello World for U【字符串】的更多相关文章

  1. PAT甲题题解-1061. Dating (20)-字符串处理,水水

    #include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...

  2. PAT甲1005 Spell it right【字符串】

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

  3. PAT乙级1031

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

  4. PAT甲题题解-1031. Hello World for U (20)-字符串处理,水

    #include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...

  5. PAT甲题题解-1001. A+B Format (20)-字符串处理,水

    计算A+B的和,并且按标准格式处理,每3个就要有个逗号 #include <iostream> #include <cstdio> #include <algorithm ...

  6. PAT甲题题解-1060. Are They Equal (25)-字符串处理(科学计数法)

    又是一道字符串处理的题目... 题意:给出两个浮点数,询问它们保留n位小数的科学计数法(0.xxx*10^x)是否相等.根据是和否输出相应答案. 思路:先分别将两个浮点数转换成相应的科学计数法的格式1 ...

  7. PAT甲题题解-1073. Scientific Notation (20)-字符串处理

    题意:给出科学计数法的格式的数字A,要求输出普通数字表示法,所有有效位都被保留,包括末尾的0. 分两种情况,一种E+,一种E-.具体情况具体分析╮(╯_╰)╭ #include <iostrea ...

  8. PAT甲题题解-1108. Finding Average (20)-字符串处理

    求给出数的平均数,当然有些是不符合格式的,要输出该数不是合法的. 这里我写了函数来判断是否符合题目要求的数字,有点麻烦. #include <iostream> #include < ...

  9. PAT甲1077 Kuchiguse【字符串】【暴力】【Hash】【二分】

    1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Personal ...

随机推荐

  1. H5开发HybridApp

    1 H5开发 开发HybridApp一般都是先完成H5部分,所谓的H5就是Html5页面,开发的时候我们在PC机上的浏览器调试即可,这里推荐Chrome F12模式. 在调试服务器请求数据部分要给ch ...

  2. Go面向对象(三)

    go语言中的大多数类型都是值予以,并且都可以包含对应的操作方法,在需要的时候你可以给任意类型增加新方法.二在实现某个接口时,无需从该接口集成,只需要实现该接口要求的所有方法即可.任何类型都可以被any ...

  3. 入门常用SQL及官方文档的使用

    SQL语句基础理论 SQL是操作和检索关系型数据库的标准语言,标准SQL语句可用于操作关系型数据库. 5大主要类型: ①DQL(Data Query Language,数据查询语言)语句,主要由于se ...

  4. 【NodeJS】热更新

    1.npm install -g supervisor 2.supervisor WellDetect.js

  5. PHP代码审计笔记--文件包含漏洞

    有限制的本地文件包含: <?php include($_GET['file'].".php"); ?> %00截断: ?file=C://Windows//win.in ...

  6. windows自启动脚本

    直接写一个普通批处理文件,如果是需要让它在系统启动时运行, 就将它放在C:\Windows\System32\GroupPolicy\Machine\Scripts\Startup目录下, 如果是需要 ...

  7. jekins构建通知邮件配置及邮件附件设置,jenkins构建通知邮件没有RF的log和report文件

    全局配置: 系统管理-系统设置-Extended E-mail Notification (本邮件是程序自动下发的,请勿回复!)<br/><br/>项目名称:$PROJECT_ ...

  8. /var/spool/postfix/maildrop/ 中有大量的文件

    今天查看硬盘剩余的容量,发现‘/’目录下占用了大量的空间:可我在这个目录下面没有放什么东西:仔细查看在/var/spool/postfix/maildrop/ 中发现了大量的文件.怎么会有这么多的文件 ...

  9. Redis 操作哈希数据

    通常我们将一些结构化的信息打包成哈希映射表,结构如下,key/value 键值对模式不变,但 value 是一个键值对 name: "Tom" age: ...... > h ...

  10. commons-beanutils的使用

    commons-beanutils是通过内省来完成的. 需要两个包: commons-beanutils-1.8.3.jar commons-logging-1.1.1.jar JavaBean类: ...