Hello World for U

2024-06-16 19:08
文章标签 hello world

本文主要是介绍Hello World for U,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题目1464:Hello World for U

时间限制:1 秒

内存限制:128 兆

特殊判题:

提交:2085

解决:564

题目描述:

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 n2 characters, 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.

输入:

There are multiple test cases.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.

输出:

For each test case, print the input string in the shape of U as specified in the description.

样例输入:
helloworld!
ac.jobdu.com
样例输出:
h   !
e   d
l   l
lowor
a    m
c    o
.    c
jobdu.


      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>
using namespace std;
 
int main()
{
    string s;
    int k,len,i,j;
    while(cin>>s)
    {
        len=s.size()+2;
        k=int(len/3-1);
        j=s.size()-2*k-2;
        for(i=0;i<k;++i)
        {
            cout<<s[i];
            cout<<string(j,' ');
            cout<<s[len-3-i];
            cout<<endl;
        }
        cout<<string(s,i,j+2)<<endl;
    }
    return 0;
}
/**************************************************************
    Problem: 1464
    User: 3011216016
    Language: C++
    Result: Accepted
    Time:10 ms
    Memory:1520 kb
****************************************************************/

这篇关于Hello World for U的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1067294

相关文章

【Spring boot】编写代码及测试用例入门之 Hello Spring boot _踩坑记

先贴下目录: 这是我从 start.spring.io 里下载的依赖Web的模板 // DemoApplication.javapackage com.abloume.springboot.blog.demo;import org.springframework.boot.SpringApplication;import org.springframework.boot.autocon

【JFinal】IDEA+maven上手JFinal之Hello World!

一、New Project 1、在 IDEA 环境下新建 Project 项目 2、选择创建 Maven 项目,并且不使用模板 3、输入 Maven 的 GroupId 和 ArtifactId 4、输入项目名称 二、将当前 Project 改为 POM 工程 将项目的 jfinal-web-demo 作为项目的 parent 工程,用于定义 maven 依赖包的版本信息、

CVPR 2024最新论文分享┆YOLO-World:一种实时开放词汇目标检测方法

论文分享简介 本推文主要介绍了CVPR 2024上的一篇论文《YOLO-World: Real-Time Open-Vocabulary Object Detection》,论文的第一作者为Tianheng Cheng和Lin Song,该论文提出了一种开放词汇目标检测的新方法,名为YOLO-World。论文通过引入视觉-语言建模和大规模预训练解决了传统YOLO检测器在固定词汇检测中的局限性。论

hello,大家好。

由于最近工作变动,目前是从河北来到了广东。 顾不上写博客了,请大家谅解。 后续会慢慢的恢复正常的节奏,很感谢大家的关注。

Adobe After Effects的插件--------CC Particle World

CC Particle World是一个粒子效果器,用于在三维空间中生成和模拟各种粒子系统,包括火焰、雨、雪、爆炸、烟雾等等。它会自动随时间变化发射粒子。 本文部分参照 https://www.163.com/dy/article/IEJVDN760536FE6V.html 使用条件 使用该插件的图层需是2D图层。 我们新建一个纯色图层(也可以是其他类型图层),作为【效果控件载体图层】

java-在idea中antrl的hello world

java-在idea中antrl的hello world 1. 在idea中安装ANTLR V4的插件2. 下载ANTLR的jar包3. idea中创建普通的java项目4. 创建一个Hello.g4的文件5. 使用idea生产接口文件6. java创建一个类和main方法7. 调试输出8. 参考链接 1. 在idea中安装ANTLR V4的插件 路径如下,安装完成后重启ide

World of Warcraft [CLASSIC][80][Shushia][Molten Core][BOSS-5 Baron Geddon]

80级术士单杀[熔火之心]40人团队副本 [5号BOSS 迦顿男爵] BOSS技能①[点燃法力],每3秒燃烧400点法力值,实际上还附带400点伤害,持续5分钟 BOSS技能②[人体炸弹] :迦顿男爵会随机给一个人施放DEBUFF,被DEBUFF影响的人需要在最短时间内跑到远离人群的角落,等待炸弹爆炸。这个技能会造成3000+的伤害,并且会对周围一定范围内的玩家造成等量伤害,感觉我

java-antrl手敲命令的hello world

java-antrl手敲命令的hello world 环境步骤1. 下载ANTLR的jar包2. 新建一个g4文件3. 生成语法对应的java文件4. 编译语法对应的java文件5. 测试语法5.1 打印测试信息5.2 查看语法分析树 6. 注意事项6.1 每一个antlr4版本的jar包都对应java的相应版本,要对应。6.2 [@1,6:10='parrt',<ID>,1:6]解析6.3

汇编语言输出“Hello World!“

1.软件 Nasmide64.exe(李忠老师编写) Fixvhdw64.exe(李忠老师编写) VirtualBox虚拟机(免费 开源) 2.过程 01.Fixvhdw64.exe输入以下代码: mov ax,0xb800mov ds,axmov byte [0x00],'H'mov byte [0x02],'e'mov byte [0x04],'l'mov byte [0