Center Alignment
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93359#problem/B(456321)
http://codeforces.com/problemset/problem/5/B
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.
You are to implement the alignment in the shortest possible time. Good luck!
Input
The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.
Output
Format the given text, aligning it center. Frame the whole text with characters «*» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.
Sample Input
This is Codeforces
Beta
Round
5
************
* This is *
* *
*Codeforces*
* Beta *
* Round *
* 5 *
************
welcome to the
Codeforces
Beta
Round 5 and
good luck
****************
*welcome to the*
* Codeforces *
* Beta *
* Round 5 *
* *
* and *
* good luck *
****************
文章排版问题,让文字居中显示。如果两边不对称时,一个靠左显示,下一个不对称的靠右显示。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <map>
#include <algorithm>
using namespace std; #define N 1100 struct node
{
char s[N];
int len;
}a[N]; int main()
{
int n=, MaxLen=, i, j;
char s1[N]; memset(a, , sizeof(a)); while(gets(s1))
{
strcpy(a[n].s, s1);
a[n].len = strlen(s1);
if(a[n].len>MaxLen)
MaxLen = a[n].len;
n++;
} /// printf("%d\n", MaxLen);
for(int i=; i<MaxLen+; i++)
printf("*"); printf("\n"); int flag = , ans;
for(i=; i<n; i++)
{
printf("*");
int len = MaxLen-a[i].len; if(len%)
flag = !flag; ans = (flag+len)/;
for(j=; j<=ans; j++)
printf(" ");
printf("%s", a[i].s); for(j=; j<=len-ans; j++)
printf(" "); printf("*\n");
} for(int i=; i<MaxLen+; i++)
printf("*"); printf("\n"); return ;
}
Center Alignment的更多相关文章
- Codeforces Beta Round #5 B. Center Alignment 模拟题
B. Center Alignment 题目连接: http://www.codeforces.com/contest/5/problem/B Description Almost every tex ...
- 歌词文件解析(二):LRC格式文件的绘制
通过对LRC文件的解析,可以轻松实现歌词可视化. 代码实现 函数名: paintLyrics(ByVal pBox As PictureBox, ByVal CurrentPosition As In ...
- C#操作Word的辅助类(word2003) 修改完善版
转自:http://blog.csdn.net/jiutao_tang/article/details/6567608 该类在他人编写的几个类基础上扩展完善而来,主要功能有: (1)插入文本 (2)插 ...
- C# 动态绘制任务栏图标的实现
通常我们在做一个应用时会遇到这样的需求:将收到的消息条数显示到任务栏,比如如下的效果 怎么实现呢? 答案是采用WindowsAPICodePack实现,具体参见:Windows 7 任务栏开发 之 覆 ...
- Lesson 2: Dive Into Typography (排版)
Lesson 2: Dive Into Typography (排版) 排版是字的艺术,是关于字的一切:字体.字号.行高.行长.字重(斜体/加粗/正常).字距(kerning).行距(leading) ...
- iOS8 用AVAudioPlayer播放音乐(Swift)
AVAudioPlayer 类提供了播放音频文件的功能,在本次教程中,我们将对一个音乐文件进行播放暂停和停止操作,此外还会显示标题和播放时间.本次教程使用iOS8和Xcod6.3.1 打开Xcode创 ...
- cocos2d-x-3.1 Text Labels(官方正式译文)
介绍 cocos2d支持(true type字体)标签,和纹理地图集标签. LabelTTF 标签的优缺点: 全部 TTF 字体的长处: 随意大小,支持调整字距. 易于使用. 不须要外部编辑器. 创建 ...
- mplayer最全的命令
前段时间做过qt内嵌mplayer的一个小程序,感觉mplayer还行不过不支持打开图片感觉有点无力.话不多说上代码: QString path="d:/1.mkv"; QWidg ...
- New UWP Community Toolkit - AdaptiveGridView
概述 UWP Community Toolkit 中有一个自适应的 GridView 控件 - AdaptiveGridView,本篇我们结合代码详细讲解 AdaptiveGridView 的实现 ...
随机推荐
- Technology, globalisation and the squeeze on good jobs
Technology, globalisation and the squeeze on good jobs技术与全球化冲击好工作“Highest stock market EVER! Jobs ar ...
- 转:Linux设备驱动开发(1):内核基础概念
一.linux设备驱动的作用 内核:用于管理软硬件资源,并提供运行环境.如分配4G虚拟空间等. linux设备驱动:是连接硬件和内核之间的桥梁. linux系统按个人理解可按下划分: 应用层:包括PO ...
- lzo文件压缩,解压
LZOP命令安装 yum install lzop lzop命令基本操作命令 # lzop -v test # 创建test.lzo压缩文件,输出详细信息,保留test文件不变 # lzop -Uv ...
- ArcGIS案例学习笔记1_1
ArcGIS案例学习笔记1_1 联系方式:谢老师,135_4855_4328, xiexiaokui#qq.com 时间:第一天上午 准备 0.U盘复制ArcGIS培训*** 1.练习数据不要放到桌面 ...
- 大型运输行业实战_day09_1_日期转换与My97DatePicker插件使用
1.日期转换 1.1字符串类型转换成时间Date类型 /** * 给定字符串 转变 为 Date 类型 * @param date 时间 * @param format 时间格式 如:yyyy-MM- ...
- do you\have you\are you
如果想问对方动作方面的 就用do you 例如 你知道吗? do you konw 如果想问对方是不是什么 就用are you 例如 你是一名教师吗 are you a teacher ? 如果想问对 ...
- Git操作的一些注意
这是在在学习Git时遇到的一些需要注意的地方,都是一些小细节的地方,可能会有错误的地方,希望大家可以指出谢谢 1.git使用,安装后,首先要打开git bash 2.必须登录后才可以操作git ...
- 结对项目3-bug的三种状态
这周和小伙伴结对构造程序,来深刻理解软件测试中,bug发现的三种状态. 1:不能触发Fault 2:触发Fault,但是不能触发Error 3:触发Error,但是不能产生Failure 我们完成的代 ...
- Educational Codeforces Round 58
D. GCD Counting 题意: 给出n个点的树,每个点有一个权值,找出一条最长的路径使得路径上所有的点的gcd>1 题解: gcd>1的一定不会有很多.所以暴力搞一下就行,不需要点 ...
- python连接redis,redis集群
python连接redis: import redis r = redis.Redis(host='192.168.50.181',port=6002) r.set('user_phone_14900 ...