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 的实现 ...
随机推荐
- Haskell语言学习笔记(62)Divisible
Divisible class Contravariant f => Divisible f where divide :: (a -> (b, c)) -> f b -> f ...
- ComputeSignature 中行支付签名报错(win7 64位系统)
在做中行加密验签的时候出现的问题.原本在XP系统下可以正常运行的,现在换了win7 64位系统就出现了这个问题,没头绪 所以发上来求各位大大支招 有什么好的解决方案.. 我的解决办法: 1.C:\Do ...
- zabbix出现中文不能选的情况
像这里一样,有些选项是选不了的,这个时候我们要做的第一步就是,找到这个配置文件. 如果不知道在哪里的话可以用find命令查找. sudo find / -name locales.inc.php 找到 ...
- android笔记 : Content provider内容提供器
内容提供器(Content Provider)主要用于在不同的应用程序之间实现数据共享的功能. 内容提供器的用法一般有两种,一种是使用现有的内容提供器来读取和操作相应程序中的数据,另一种是创建自己的内 ...
- 兼容多浏览器的网页复制插件(ZeroClipboard)
前言: 常规利用JS编写的网页复制功能是最简单的方法,但是只对IE有效,无法做到兼容其它浏览器,对其他浏览器也就只能弹窗提示用户手动复制了. <script type="text/ja ...
- sql批量修改字段内容的语句-SQL技巧
--update '表名' set 要修改字段名 = replace (要修改字段名,'被替换的特定字符','替换成的字符')--update tRecord set columnName = rep ...
- IIS 访问不了,IIS有问题,IIS右击浏览没反应
查看是否是下面的问题 web服务扩展中,下面三项设置为 “允许” CGI扩展 ISAPI扩展 Active Server Pages
- ScrollView listView gridView 之间的冲突问题
在ScrollView中的listView gridView添加适配器之后添加//设置gridView整体的高度 public void setListViewHeightBasedOnChildre ...
- nginx安装及基础配置(含jdk安装及配置)
0.jdk安装配置 #下载相应的jdk软件包,然后解压安装,我这里包名称为:jdk-7u25-linux-x64.tar.gz tar -xzf jdk-7u25-linux-x64.tar.gz m ...
- VC2008 类型重定义的问题
Q: 比如"a.h"里定义了类a,类a所有函数的实现都放在"a.cpp"里.然后"b.h"和"c.h"都需要用到类a,所 ...