博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Hello World for U (20)
阅读量:5315 次
发布时间:2019-06-14

本文共 2295 字,大约阅读时间需要 7 分钟。

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.

 

 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

 

 

1 #include 
2 3 #include
4 5 using namespace std; 6 7 8 9 int main() 10 11 { 12 13 14 15 string ss; 16 17 while(cin>>ss) 18 19 { 20 21 int x,y; 22 23 bool u=false; 24 25 for(x=ss.length();x>=1;x--) 26 27 { 28 29 if(x<3) 30 31 { 32 33 for(y=3;y<=ss.length();y++) 34 35 if(2*x+y-2==ss.length()) 36 37 { 38 39 u=true; 40 41 break; 42 43 } 44 45 } 46 47 else 48 49 { 50 51 for(y=x;y<=ss.length();y++) 52 53 if(2*x+y-2==ss.length()) 54 55 { 56 57 u=true; 58 59 break; 60 61 } 62 63 64 65 } 66 67 if(u) break; 68 69 70 71 } 72 73 74 75 76 77 int i=0;int j=ss.length()-1;int k; 78 79 int tem=x-1; 80 81 while(tem--) 82 83 { 84 85 cout<
View Code

 

转载于:https://www.cnblogs.com/xiaoyesoso/p/4249341.html

你可能感兴趣的文章
SRM 628 DIV2
查看>>
2018-2019-2 20165314『网络对抗技术』Exp5:MSF基础应用
查看>>
Python-S9-Day127-Scrapy爬虫框架2
查看>>
SecureCRT的使用方法和技巧(详细使用教程)
查看>>
自建数据源(RSO2)、及数据源增强
查看>>
关于View控件中的Context选择
查看>>
2018icpc徐州OnlineA Hard to prepare
查看>>
Spark的启动进程详解
查看>>
使用命令创建数据库和表
查看>>
机器视觉:SSD Single Shot MultiBox Detector
查看>>
在16aspx.com上下了一个简单商品房销售系统源码,怎么修改它的默认登录名和密码...
查看>>
linux下Rtree的安装
查看>>
多米诺骨牌
查看>>
Linq 学习(1) Group & Join--网摘
查看>>
asp.net 调用前台JS调用后台,后台掉前台JS
查看>>
苹果手表:大方向和谷歌一样,硬件分道扬镳
查看>>
Android面试收集录15 Android Bitmap压缩策略
查看>>
PHP魔术方法之__call与__callStatic方法
查看>>
ubuntu 安装后的配置
查看>>
【模板】对拍程序
查看>>