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 的实现 ...
随机推荐
- Linux初学时的一些常用命令(3)
管道 | 重要的一个概念,其作用是将一个命令的输出用作另一个命令的输入 例如: 在ifconfig的结果里查找 192.168字符串 ifconfig | grep 192.168 查找和jav ...
- KEGG下载某物种最新的版本信息(斑马鱼为例)
步骤一:打开链接并选择物种 http://www.genome.jp/kegg-bin/get_htext?hsa00001+3101 步骤二:对文件进行解析 步骤三:统计信息 一级结构(6大类): ...
- day11:vcp考试
Q201. Which two options are available in the Virtual Machine Component Protection (VMCP) setting Res ...
- [leetcode]228. Summary Ranges区间统计
Given a sorted integer array without duplicates, return the summary of its ranges. Example 1: Input: ...
- php 账号不能同时登陆,当其它地方登陆时,当前账号失效
解决的思路是每当用户登陆时我们必需记录当前的用户id和session_id,如果有人在其它地方用此账号登陆时,我们把此用户id对应的session_id的session文件删除,并重新记录当前的ses ...
- discuz回贴通知插件实现-配置邮件服务器
添加smtp服务器,填写相应的smtp服务器,发信人地址,用户名和密码. 填写发件人地址和收件人地址来测试邮件是否发送成功.
- Spring的2.5版本中提供了一种:p名称空间的注入(了解)
1. 步骤一:需要先引入 p 名称空间 * 在schema的名称空间中加入该行:xmlns:p="http://www.springframework.org/schema/p"( ...
- Electronic Trading[z]
This article is to discuss the operation model between Fund Managers(Client) and Broker Firms. They ...
- LINUX 笔记5
配置环境变量:(只是在当前命令行窗口中有用) 单独查看PATH环境变量,可用: [root@localhost u-boot-sh4]#echo $PATH 添加PATH环境变量,可用: [root@ ...
- Codeforces C. NP-Hard Problem 搜索
C. NP-Hard Problem time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...