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

相关文章

hello程序的漫游历程

hello程序的运行过程 #include<stdio.h>int main(){printf("hello, world\n);return 0;} 相信大家都知道这个著名的家伙,hello world,万物起源。 本文的目的就是一起来看看,当这个hello程序在系统上运行时,系统发生了什么以及为什么会这样。 hello程序的生命周期是从一个源文件(源程序)开始的,文件名为hello

AJAX:如何编写一个关于AJAX的Hello World?(ajax发送异步请求(四步操作))

用到的一个Servlet类: package cn.edu.web.servlet;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;impor

oracle学习之第一个存储过程:打印Hello World

数据库对象:表、视图、索引、序列、同义词、存储过程、存储函数 存储过程:指的是存储在数据库中供所有用户程序调用的子程序叫存储过程、存储函数 存储过程和存储函数的相同点:完成特定功能的程序 存储过程和存储函数的区别:是否用return语句返回值(存储函数可以,但是存储过程不行) --第一个存储过程:打印Hello World/*调用存储过程2种方式:1、exec sayhellow

在Mac OS上使用Visual Studio Code创建C++ Qt的Hello World应用

引言 Qt是一个跨平台的应用程序和用户界面框架,而Visual Studio Code是一个功能强大的编辑器,两者结合可以极大地提升开发效率。本文将指导你在Mac OS上使用Visual Studio Code创建一个简单的Qt 'Hello World'窗口应用。 环境准备 确保你的MacBook OS运行最新的操作系统。安装Homebrew,Mac OS的包管理器。通过Homebrew安装

SpringBoot (一) :入门篇 Hello World

什么是SpringBoot Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。通过这种方式,Spring Boot致力于在蓬勃发展的快速应用开发领域(rapid application development)成为领导者。 SpringBoot有什么

Hello 悟空

我要听到天的痛苦,我要听到神的乞求。我知道天会愤怒,但你知道天也会颤抖吗?苍穹动摇时,我放声大笑,挥开如意金箍棒,打它个地覆天翻。从今往后一万年,你们都会记住我的名字-------齐天大圣孙悟空!        这漫长而短暂的一生,究竟该用来追求些什么呢?其实这就是一群人,用一生寻找答案的故事。

C语言socket HTTP Server hello world程序(Ubuntu Linux 24.04环境)

本程序实现的是一个能返回hello world的http server, 也只能返回hello world,作为C语言http server开发的一个起步阶段。 /*编译生成可执行程序(Ubuntu Linux 24.04)# gcc ./socket_server.c -o socket_server# scp socket_server root@idealand.space:/roo

PAT 甲级 1055 The World‘s Richest

PAT 甲级 1055 The World’s Richest 这道题一次AC,但是后来看《算法笔记·上机训练实战指南》中的解析,说由于M<100,所以每个年龄读入100个人,就可以不读入了,这样能显著提高时间,否则测试点二过不了。但是没有写这个预处理也过了,回去看了看时间是400ms,猜想应该是传参都用的是传引用调用,改成传值调用之后果然超时。 解析也是用传值调用写的,传引用不香吗。 #i

PAT 甲级 1011 World Cup Betting

PAT 甲级 1011 World Cup Betting 简单模拟 #include<bits/stdc++.h>using namespace std;const double EPS=1e-7;int main(){double a,b,c,ans=1;for(int i=0;i<3;++i){cin>>a>>b>>c;if(a-b>-EPS&&a-c>-EPS) {co

2.Hello World实验

实验现象:使用Arduino 的串口编写一句“Hello Wrold!”,然后用Arduino发送给PC机。 理论学习: 该程序中用到了Arduino程序里面最常见的几个函数: void setup() 该函数用于编写Arduino的初始化内容,本例程内设置通讯波特率就放在这里。   对于通讯的设置只需设置一次就可以了。所以把Serial.bgein(9600)放在这。   Seria