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--模块--10
原创博文,转载请标明出处--周学伟http://www.cnblogs.com/zxouxuewei/ Python 模块 Python 模块(Module),是一个 Python 文件,以 .py ...
- Java动态调用类中方法
在Java中,调用类的方法有两种方式:对于静态方法可以直接使用类名调用,对于非静态方法必须使用类的对象调用.反射机制提供了比较另类的调用方式,可以根据需要指定要调用的方法,而不必在编程时确定.调用的方 ...
- NYOJ 116 士兵杀敌 (线段树,区间和)
题目链接:NYOJ 116 士兵杀敌 士兵杀敌(二) 时间限制:1000 ms | 内存限制:65535 KB 难度:5 描写叙述 南将军手下有N个士兵,分别编号1到N,这些士兵的杀敌数都是已知的 ...
- WinForm中实现HotKey
最近在写一个游戏辅助工具,来点Win变成的总结 主要用了RegisterHotKey:UnregisterHotKey:两个winAPI 以下代码来自stackoverflow新增了一个HotKeyM ...
- ios开发之--NSDictionary和NSData之间的互转/NSString和NSData之间的互转
NSDictionary转NSData,代码如下: +(NSData*)returnDataWith:(NSDictionary*)dict { NSData *data = [NSJSONSeria ...
- 【GIS】Cesium回到初始位置
var boundingSphere = new Cesium.BoundingSphere(Cesium.Cartesian3.fromDegrees(116.4, 39.9, 100), 15 ...
- linux-友好显示文件大小
4850905319b / 1024 /1024/1024 = 4.6G ls -lh
- osgearth2.8关于RectangleNodeEditor编辑点不可见的问题
static_cast<SphereDragger*>(_llDragger)->setColor(osg::Vec4(0,0,1,0)); Alpha写成了0 应该写成 stati ...
- 基于Elasticsearch 5.4.3的商品搜索系统
源码已提交至http://github.com
- 学习下新塘M0芯片的下载方法
编程方式多种多样,解释这几种方式的原理,方便做后续的回答: 一.脱机 脱机的意思就是脱离PC机,有很多芯片必须连接PC才能烧录,比如某些FPGA芯片.MCU芯片.NAND Flash芯片等.脱机和在线 ...