题目1464:Hello World for U
来源:互联网 发布:怎样绑定域名和空间 编辑:程序博客网 时间:2024/06/16 02:15
- 题目描述:
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 dl llowora mc o. cjobdu.
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int main(){ char a[99]; int i,j,len,s,e; while(scanf("%s",a)!=EOF)//开始写的是gets(a)!=NULL,无限WRONG,本来秒过的题目,坑了好久,不过为什么不行。我还不是很清楚,求大神指点 { len=strlen(a)+2; int n1,n2; n1=len/3; n2=len-n1*2; n1-=1; s=0; e=len-2-1; while(n1--) { printf("%c",a[s++]); for(i=0;i<n2-2;i++) printf(" "); printf("%c",a[e--]); puts(""); } for(i=s;i<=e;i++) printf("%c",a[i]); puts(""); } return 0;}
- 题目1464:Hello World for U
- 题目1464:Hello World for U
- 题目1464:Hello World for U
- 题目1464:Hello World for U
- 题目1464:Hello World for U
- 九度OJ 题目1464:Hello World for U
- 九度OJ-题目1464:Hello World for U
- 九度 题目1464:Hello World for U
- Hello World for U
- Hello World for U
- Hello World for U
- Hello World for U
- Hello World for U
- 九度1464:Hello World for U
- 【学习笔记】〖九度OJ〗题目1464:Hello World for U
- 九度oj 题目1464:Hello World for U 【ZJU2012考研机试题1】
- zju2012:Hello World for U
- 1031. Hello World for U
- java5核心基础之泛型(3)-泛型作用于编译阶段-如何将String对象传入Integer类型的泛型对象中?
- TCP/IP协议各层作用
- 21.三a啊
- GetWindowDC-BeginPaint-GetDC 区别详解
- Codeforces Testing Round #9 D/386D
- 题目1464:Hello World for U
- 内网ip映射到外网软件80全端口映射
- [RBM]Restricted Boltzmann Machines
- 宿命论:为什么iPad的最大敌人会是iPhone?
- opendaylight控制器集群
- 在Linux下进行串口通信相关参数的设定
- 三方支付
- IE和火狐等浏览器html标签显示不同的解决办法
- Matlab 集群计算使用心得