题目描述:
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!

样例输出:

h   !
e   d
l   l
lowor
#include<cstdio>
#include<cstring>
using namespace std;int main(){char str[100];gets(str);int N = strlen(str);int n1 = (N + 2) / 3, n3 = n1,n2 = N + 2 - n1 - n3;for (int i = 0; i < n1 - 1; i++){//数字从零开始,所以左边一列是0到n1-1,此处输出的是除了最后一行的Uprintf("%c", str[i]);for (int j = 0; j < n2 - 2; j++){printf(" ");}printf("%c\n", str[N - i - 1]);}for (int i = n1 - 1; i <= n2 + n1 - 2; i++){printf("%c", str[i]);}//下面一行从n1-1开始,一共n2个,到n2+n1-1-1结束  (就是 尾-头=数字个数-1)return 0;
}

HelloWorldForU相关推荐

最新文章

  1. 老板说 10 分钟可改完 Bug,为什么我却干了 3 小时?
  2. Android 解析 Unable to add window is your activity running?
  3. zookeeper收尾+dubbo前瞻
  4. shell 用环境变量的值修改properties文件
  5. PyCharm pyqt5 python串口通信封装类SerialCommunication
  6. 入门 | 使用 SQL 构建一个关系数据库比你想的更容易
  7. 机器学习算法的差异_我们的机器学习算法可放大偏差并永久保留社会差异
  8. 软件安装 | 神器VAX Patch VA_X.DLL 安装位置的问题 for VS2008 , VS2010 , VS2011
  9. Python实现统计二叉树叶子结点个数
  10. 解决HD3000在OS X 10.10.2上横线和花屏问题
  11. 在东京生活的中国IT程序员
  12. “无为而无不为”杂议
  13. grub加密 bios加密 linux
  14. Google Chorme
  15. 第十四章 齐桓公广开门路招贤才 卫宁戚饭牛而歌得重用
  16. WP Mail SMTP配置谷歌邮箱
  17. 苹果发布会MacBook Pro/AirPods 3 M系最强芯片来炸场!
  18. LIO-SAM:Ubuntu20.04下的编译与运行
  19. 重磅!华为搜索引擎面世
  20. java模拟登录qq邮箱_使用Java实现qq邮箱发送邮件

热门文章

  1. 这就是你日日夜夜想要的docker!!!---------Docker Compose容器编排理论+实操
  2. amd速龙黑苹果内核补丁_Lilu.kext v1.4.2 黑苹果内核扩展补丁
  3. 关于微信JSAPI申请退款
  4. 【小彬学vue系列专栏】 002 | 一颗树的惆怅
  5. git的bash脚本
  6. 【python基础】4.1 面向对象(待修改)
  7. Python神经网络1之TensorFlow
  8. PyTorch深度学习(25)网络结构ConvNeXt
  9. JAVA开发运维(CI/CD)
  10. LTK5135M MSOP-8封装 耐压7V_F类、单声道音频放大器/兼容于4890,音质更好适用于车载导航仪、对讲机、便携游戏机等