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 的实现 ...
随机推荐
- MySQL的事务处理及隔离级别
事务是DBMS得执行单位.它由有限得数据库操作序列组成得.但不是任意得数据库操作序列都能成为事务.一般来说,事务是必须满足4个条件(ACID) 原子性(Autmic):事务在执行性,要 ...
- Quartz+TopShelf实现Windows服务作业调度
Quartz:首先我贴出来了两段代码(下方),可以看出,首先会根据配置文件(quartz.config),包装出一个Quartz.Core.QuartzScheduler instance,这是一个调 ...
- 流和Variant的转换
procedure TForm2.VariantToStream (const v : olevariant; Stream : T ...
- DEXSeq
1)Introduction DEXSeq是一种在多个比较RNA-seq实验中,检验差异外显子使用情况的方法. 通过差异外显子使用(DEU),我们指的是由实验条件引起的外显子相对使用的变化. 外显子的 ...
- Java连接MySQL数据库及操作
Java操作MySQL数据库,需要驱动mysql-connector-java 来进行操作,去下载对应的jar包 一.导入需要的jar包 我用的是maven对包进行管理,在maven中添加如下内容 ...
- Python sum() 函数
Python sum() 函数 Python 内置函数 描述 sum() 方法对系列进行求和计算. 语法 以下是 sum() 方法的语法: sum(iterable[, start]) 参数 ite ...
- android:cmd下面用adb打log
进入cmd命令行,启动adb 1.用adb打log:adb logcat 2.过滤log信息:adb logcat | findstr *** 这里的***就是你需要设置的过滤项,如myscan ...
- 关于block元素和inline元素
呃...这个会不会太基础了.最近在复习,所以基础知识也不能够忽略. 根据HTML 4.01 规范,其描述如下(http://www.w3.org/TR/html401/struct/global.ht ...
- 轮播图jQuery
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- mysql rc模式时binlog_format=row的解释【转】
总体来说:在 tx_isolation= READ-COMMITTED .binlog_format =statement 的情况下,mysql 没有gap 锁,这样binlog 记录的数据修改的顺序 ...