http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93359#problem/B(456321)

http://codeforces.com/problemset/problem/5/B

Center Alignment

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

Input
This  is

Codeforces
Beta
Round
5
Output
************
* This is *
* *
*Codeforces*
* Beta *
* Round *
* 5 *
************
Input
welcome to the
Codeforces
Beta
Round 5 and
good luck
Output
****************
*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的更多相关文章

  1. Codeforces Beta Round #5 B. Center Alignment 模拟题

    B. Center Alignment 题目连接: http://www.codeforces.com/contest/5/problem/B Description Almost every tex ...

  2. 歌词文件解析(二):LRC格式文件的绘制

    通过对LRC文件的解析,可以轻松实现歌词可视化. 代码实现 函数名: paintLyrics(ByVal pBox As PictureBox, ByVal CurrentPosition As In ...

  3. C#操作Word的辅助类(word2003) 修改完善版

    转自:http://blog.csdn.net/jiutao_tang/article/details/6567608 该类在他人编写的几个类基础上扩展完善而来,主要功能有: (1)插入文本 (2)插 ...

  4. C# 动态绘制任务栏图标的实现

    通常我们在做一个应用时会遇到这样的需求:将收到的消息条数显示到任务栏,比如如下的效果 怎么实现呢? 答案是采用WindowsAPICodePack实现,具体参见:Windows 7 任务栏开发 之 覆 ...

  5. Lesson 2: Dive Into Typography (排版)

    Lesson 2: Dive Into Typography (排版) 排版是字的艺术,是关于字的一切:字体.字号.行高.行长.字重(斜体/加粗/正常).字距(kerning).行距(leading) ...

  6. iOS8 用AVAudioPlayer播放音乐(Swift)

    AVAudioPlayer 类提供了播放音频文件的功能,在本次教程中,我们将对一个音乐文件进行播放暂停和停止操作,此外还会显示标题和播放时间.本次教程使用iOS8和Xcod6.3.1 打开Xcode创 ...

  7. cocos2d-x-3.1 Text Labels(官方正式译文)

    介绍 cocos2d支持(true type字体)标签,和纹理地图集标签. LabelTTF 标签的优缺点: 全部 TTF 字体的长处: 随意大小,支持调整字距. 易于使用. 不须要外部编辑器. 创建 ...

  8. mplayer最全的命令

    前段时间做过qt内嵌mplayer的一个小程序,感觉mplayer还行不过不支持打开图片感觉有点无力.话不多说上代码: QString path="d:/1.mkv"; QWidg ...

  9. New UWP Community Toolkit - AdaptiveGridView

    概述 UWP Community Toolkit  中有一个自适应的 GridView 控件 - AdaptiveGridView,本篇我们结合代码详细讲解  AdaptiveGridView 的实现 ...

随机推荐

  1. Hibernate hql 多表查询

    String hql="select c from Col c ,UserRole role where c.id=role.columnId and c.id=? and role.use ...

  2. 迷你MVVM框架 avalonjs 学习教程20、路由系统

    SPA的成功离开不这三个东西,分层架构,路由系统,储存系统.分层架构是我们组织复杂代码的关键,这里特指MVVM的avalon:路由系统是将多个页面压缩在一个页面的关键:储存系统特指本地储存,是安全保存 ...

  3. 刚刚安装完nginx,服务启动,通过浏览器无法访问的问题

    查看Linux服务是否启动. ps -ef | grep nginx 解决办法:1,添加 80 段端口配置 firewall-cmd --zone=public --add-port=80/tcp - ...

  4. freemaker基础语法

      1.freemarker中Request,Session的用法:java块:request.getSession().setAttribute("qq","http: ...

  5. 疯狂JAVA——第二章 理解面向对象

    面向对象的三大特征:继承.封装和多态 面向对象的方式实际上由OOA(面向对象分析).OOD(面向对象设计)和OOP(面相对象编程)三个部分组成,其中OOA和OOD的结构需要用一个描述方式来描述并记录, ...

  6. linux sleep用法

    应用程序:#include <syswait.h>usleep(n) //n微秒Sleep(n)//n毫秒sleep(n)//n秒驱动程序:#include <linux/delay ...

  7. 大型运输行业实战_day07_2_数据字典实现

    1.数据字典表 CREATE TABLE `dic` ( `id` ) NOT NULL AUTO_INCREMENT, `table_name` ) DEFAULT NULL, `field_nam ...

  8. express中使用ejs

    [express中使用ejs] 1.添加 ejs 依赖. npm install ejs --save 2.设置 view engine 为 ejs 即可.

  9. Windows phone Toast消息推送 学习笔记

    简单介绍: Windows phone平台支持三种形式的推送通知: 1.Tile——也就是在Start屏幕程序平铺图标 2.Toast——创建一个显示在当前屏幕中的Toast弹出窗口 3.Raw——有 ...

  10. Dungeon Game (GRAPH - DP)

    QUESTION The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a ...