PAT甲1031 Hello World for U【字符串】
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 n1 characters, then left to right along the bottom line with n2characters, 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型输出。
思路:
找到小于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【字符串】的更多相关文章
- PAT甲题题解-1061. Dating (20)-字符串处理,水水
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...
- 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 ...
- PAT乙级1031
题目链接 https://pintia.cn/problem-sets/994805260223102976/problems/994805290334011392 题解 emmm.对于每个身份证号, ...
- PAT甲题题解-1031. Hello World for U (20)-字符串处理,水
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...
- PAT甲题题解-1001. A+B Format (20)-字符串处理,水
计算A+B的和,并且按标准格式处理,每3个就要有个逗号 #include <iostream> #include <cstdio> #include <algorithm ...
- PAT甲题题解-1060. Are They Equal (25)-字符串处理(科学计数法)
又是一道字符串处理的题目... 题意:给出两个浮点数,询问它们保留n位小数的科学计数法(0.xxx*10^x)是否相等.根据是和否输出相应答案. 思路:先分别将两个浮点数转换成相应的科学计数法的格式1 ...
- PAT甲题题解-1073. Scientific Notation (20)-字符串处理
题意:给出科学计数法的格式的数字A,要求输出普通数字表示法,所有有效位都被保留,包括末尾的0. 分两种情况,一种E+,一种E-.具体情况具体分析╮(╯_╰)╭ #include <iostrea ...
- PAT甲题题解-1108. Finding Average (20)-字符串处理
求给出数的平均数,当然有些是不符合格式的,要输出该数不是合法的. 这里我写了函数来判断是否符合题目要求的数字,有点麻烦. #include <iostream> #include < ...
- PAT甲1077 Kuchiguse【字符串】【暴力】【Hash】【二分】
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Personal ...
随机推荐
- python concurrent.futures包使用,捕获异常
concurrent.futures的ThreadPoolExecutor类暴露的api很好用,threading模块抹油提供官方的线程池.和另外一个第三方threadpool包相比,这个可以非阻塞的 ...
- WebBrowser中html元素如何触发winform事件
这个问题来自论坛提问,对dom稍微了解的话还是比较简单的,只要注册一下事件就可以了. C#代码如下: using System;using System.ComponentModel;using Sy ...
- Quatz入门
Demo SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory(); Scheduler sched = sched ...
- mybatis generator配置,Mybatis自动生成文件配置,Mybatis自动生成实体Bean配置
mybatis generator配置,Mybatis自动生成文件配置,Mybatis自动生成实体Bean配置 ============================== 蕃薯耀 2018年3月14 ...
- 【代码审计】Cscms_v4.1 任意文件删除漏洞实例
环境搭建: CSCMS :http://www.chshcms.com/ 网站源码版本:Cscms_v4.1正式版(发布日期:2017-06-05) 程序源码下载:https://github.com ...
- 在 Core Data 中存取 transformable 类型的数据
本文转载至 http://imenjoe.com/2015/04/10/CoreData-transformable-20150410/ 在开发过程中有一个需要在 Core Data 中存取 NSDi ...
- open-falcon之graph
功能 存储agent push的数据 为query 提供查询数据接口 参考RRDtool的理念,在数据每次存入的时候,会自动进行采样.归档.在默认的归档策略,一分钟push一次的频率下, 历史数据保存 ...
- Twitter的SnowFlake分布式id生成算法
二进制相关知识回顾 1.所有的数据都是以二进制的形式存储在硬盘上.对于一个字节的8位到底是什么类型 计算机是如何分辨的呢? 其实计算机并不负责判断数据类型,数据类型是程序告诉计算机该如何解释内存块. ...
- vue经验 - 那些自己给自己挖的深坑
深坑场景:vue-异步请求数据,数据还没回来,页面却如饥似渴的准备好了的尴尬场景:问题原因和解决如下: 1.先说vuex中的store,一开始我为了偷懒是这么设置的,如下图: 然后我到了组件中直接这么 ...
- 原生js--insertAdjacentHTML
insertAdjacentHTML是IE浏览器提供向DOM中插入html字符串的方法,字符串会自动生成在DOM树中. 其调用方式为elem.insertAdjacentHTML( position, ...