九度1464:Hello World for U
来源:互联网 发布:手机淘宝怎么退货退款 编辑:程序博客网 时间:2024/06/08 15:14
题目1464:Hello World for U
时间限制:1 秒
内存限制:128 兆
特殊判题:否
提交:2967
解决:834
题目描述:
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.
来源:
2012年浙江大学计算机及软件工程研究生机试真题
思路:注意"n1 + n2 + n3 - 2 = N.",最好将n1,n2,n3都取得平均值,即n1=n2=(n+2)/3-1
#include<stdio.h>#include<string.h>char a[100];int main(){ int i,j,n,n1,n2,n3,m1,m2; while(scanf("%s",a)!=EOF) { n=strlen(a); n1=n2=(n+2)/3-1; n3=n-2*n1; for(i=0;i<n1;i++) { printf("%c",a[i]); for(j=0;j<n3-2;j++) printf(" "); printf("%c\n",a[n-i-1]); } m1=i;m2=n-i; for(i=m1;i<m2;i++) printf("%c",a[i]); puts(""); memset(a,0,sizeof(0)); } return 0;}
- 九度1464:Hello World for U
- 1464 Hello World for U 九度Online Judge
- 九度OnlineJudge之1464:Hello World for U
- 九度:1464<Hello World For U><排版>
- 九度 OJ 1464 Hello World for U
- 九度OJ 1464 Hello World for U
- 九度OJ 题目1464:Hello World for U
- 九度OJ-题目1464:Hello World for U
- 九度oj-1464-Hello World for U
- 九度 题目1464:Hello World for U
- 九度OJ-1464:Hello World for U
- 【学习笔记】〖九度OJ〗题目1464:Hello World for U
- 九度oj 题目1464:Hello World for U 【ZJU2012考研机试题1】
- 九度考研真题 浙大 2012-1浙大1464:Hello World for U
- Hello World for U
- Hello World for U
- Hello World for U
- Hello World for U
- 看你的飞洒洛克菲勒看能否
- iReport专题学习之报表元素03
- 使用ENVI打开raw格式影像
- 玩玩儿Flyway:数据库迁移
- pentesterlab学习记录-week3
- 九度1464:Hello World for U
- HDU 2594 Simpsons’ HiddenTalents(KMP:后缀与前缀)
- Java List/ArrayList操作示例----添加/排序/取子块/删除/追加元素
- 启动app时 出现程序默认标题栏 解决办法
- Java第4周实验
- 第六周项目2-对象作为数据成员
- 求3个处理机同时工作完成7个任务所用时间
- AOV网络与拓扑(二)——实现
- 黑马程序员 OC------内存管理学习