首页 > 试题广场 >

Hello World for U

[编程题]Hello World for U
  • 热度指数:14325 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
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.
示例1

输入

helloworld!
www.nowcoder.com

输出

h   !
e   d
l   l
lowor
w    m
w    o
w    c
.    .
n    r
owcode
头像 Taitres
发表于 2021-05-11 11:19:51
1.代码实现 #include<iostream> #include<cstdio> using namespace std; int main() { char str[81]; while(scanf("%s",&str)!=EOF){ 展开全文
头像 LoveJK
发表于 2022-01-12 21:49:37
n2随长度增加呈现出一个有规律的数列,从最短长度5开始,n2为:3,4,3,4,5,4,5,6,5,6,7,6,7,8,7,8,9,8,9,10...... #include<iostream> #include<cstring> using namespace std; 展开全文
头像 路人萌Miranda
发表于 2022-03-17 13:42:18
#include <cstdio> #include <string> using namespace std; int main() { string str; while (cin >> str) { int len = str.size(); 展开全文
头像 顶呱呱的火龙果很不想上网课
发表于 2023-02-03 16:46:20
#include <stdio.h> #include <string.h> #include <stdlib.h> int main() { int n, h, w; char s[100]; fgets(s, 100, stdin); 展开全文
头像 牛客861440576号
发表于 2023-02-25 18:16:19
#include "cstdio" #include "string" using namespace std; // 大家用笔和纸画一下就知道了 // 因为 x <= y; 且 2x + y = N - 2 // n1 = n3 = max { k| k <= n2 for al 展开全文
头像 _洋洋_
发表于 2024-03-20 21:53:54
#include<iostream> #include<cstdio> #include<string> using namespace std; int main(){ char arr[100][100]; char buff[100];//暂 展开全文
头像 Caiguu
发表于 2021-06-20 16:42:02
知识点 绘图,模拟,枚举。可以认为是鸡兔同笼的变式题 关键点 And more, we would like U to be as squared as possible -- that is, it must be satisfied that n1 = n3 = max { k| k < 展开全文
头像 DioDid
发表于 2022-01-15 19:56:39
/** * @file StringForU.cpp * @author Shay (837328426@qq.com) * @brief 将字符串变成一个最接近U的形状 * 下面比上面长一个字符 * @date 2022-01-15 */ #include <iostream& 展开全文
头像 Perceive109
发表于 2023-01-10 13:06:25
#include <iostream> #include "string" #include "vector" using namespace std; void getHandW(int size, int &height, int &width) { // 根据初始输入的字符串 展开全文
头像 pyp0703
发表于 2024-03-17 14:33:16
#include <stdio.h> int get_length(char s[]) { int i = 0; while (s[i++]); return i - 1; } int main() { char s[80] = {}; while (scanf(" 展开全文

问题信息

难度:
63条回答 6399浏览

热门推荐

通过挑战的用户

查看代码