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 ...
随机推荐
- 大杂烩 -- Java中Iterator的fast-fail分析
基础大杂烩 -- 目录 Java中的Iterator非常方便地为所有的数据源提供了一个统一的数据读取(删除)的接口,但是新手通常在使用的时候容易报如下错误ConcurrentModificationE ...
- 【代码审计】iZhanCMS_v2.1 前台存储型XSS漏洞分析
0x00 环境准备 iZhanCMS官网:http://www.izhancms.com 网站源码版本:爱站CMS(zend6.0) V2.1 程序源码下载:http://www.izhancms ...
- Splash js_enabled 属性
js_enabled属性是 Splash 的 JavaScript 执行开关,可以将其配置为 true 或 false 来控制是否执行 JavaScript 代码,默认为 true .例如,这里禁止执 ...
- 第一篇:Hadoop简介
前言 本文大致介绍下Hadoop的一些背景知识,为后面深入学习打下铺垫. 什么是Hadoop Hadoop是一个开源分布式计算平台,它以HDFS文件系统和MapReduce计算框架为核心. 前者能够让 ...
- mybatis 之 resultType="Map" parameterType="String"
<select id="getAllGoodsForSouJiaYi" resultType="Map" parameterType="Stri ...
- CentOS配制FTP服务器,并且能用root权限登录
步骤如下: 1.运行yum install vsftpd命令 具体的细节如下:(如果无法更新,你先配置能访问互联网,我有文档叫 CentOS 在 VMware下,如何联网到Internet的解决办法可 ...
- C++ template —— 函数对象和回调(十四)
本篇是本系列博文最后一篇,主要讲解函数对象和回调的相关内容.函数对象(也称为仿函数)是指:可以使用函数调用语法进行调用的任何对象.在C程序设计语言中,有3种类似于函数调用语法的实体:函数.类似于函数的 ...
- iOS - 白名单应用间相互跳转
1. 应用间相互跳转简介 在iOS开发的过程中,我们经常会遇到需要从一个应用程序A跳转到另一个应用程序B的场景.这就需要我们掌握iOS应用程序之间的相互跳转知识. 下面来看看我们在开发过程中遇到的应用 ...
- <转>Python: and、or以及and-or
转自 http://www.cnblogs.com/BeginMan/p/3197123.html 一.and: 在Python 中,and 和 or 执行布尔逻辑演算,如你所期待的一样,但是它们并不 ...
- 【Linux基础学习】Ubuntu 常用命令大全
一.文件目录类 1.建立目录:mkdir 目录名 2.删除空目录:rmdir 目录名 3.无条件删除子目录: rm -rf 目录名 4.改变当前目录:cd 目录名 (进入用户home目录:cd ~:进 ...