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
  1. This is
  2.  
  3. Codeforces
    Beta
    Round
    5
Output
  1. ************
    * This is *
    * *
    *Codeforces*
    * Beta *
    * Round *
    * 5 *
    ************
Input
  1. welcome to the
    Codeforces
    Beta
    Round 5
  2.  
  3. and
    good luck
Output
  1. ****************
    *welcome to the*
    * Codeforces *
    * Beta *
    * Round 5 *
    * *
    * and *
    * good luck *
    ****************
  1. 文章排版问题,让文字居中显示。如果两边不对称时,一个靠左显示,下一个不对称的靠右显示。
  1.  
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cstdlib>
  4. #include <iostream>
  5. #include <map>
  6. #include <algorithm>
  7. using namespace std;
  8.  
  9. #define N 1100
  10.  
  11. struct node
  12. {
  13. char s[N];
  14. int len;
  15. }a[N];
  16.  
  17. int main()
  18. {
  19. int n=, MaxLen=, i, j;
  20. char s1[N];
  21.  
  22. memset(a, , sizeof(a));
  23.  
  24. while(gets(s1))
  25. {
  26. strcpy(a[n].s, s1);
  27. a[n].len = strlen(s1);
  28. if(a[n].len>MaxLen)
  29. MaxLen = a[n].len;
  30. n++;
  31. }
  32.  
  33. /// printf("%d\n", MaxLen);
  34. for(int i=; i<MaxLen+; i++)
  35. printf("*");
  36.  
  37. printf("\n");
  38.  
  39. int flag = , ans;
  40. for(i=; i<n; i++)
  41. {
  42. printf("*");
  43. int len = MaxLen-a[i].len;
  44.  
  45. if(len%)
  46. flag = !flag;
  47.  
  48. ans = (flag+len)/;
  49. for(j=; j<=ans; j++)
  50. printf(" ");
  51. printf("%s", a[i].s);
  52.  
  53. for(j=; j<=len-ans; j++)
  54. printf(" ");
  55.  
  56. printf("*\n");
  57. }
  58.  
  59. for(int i=; i<MaxLen+; i++)
  60. printf("*");
  61.  
  62. printf("\n");
  63.  
  64. return ;
  65. }

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. UGUI Auto Layout 自动布局

    Layout Element 首先分配 Minimum Size 如果还有足够空间,分配 Preferred Size 如果还有额外空间,分配 Flexible Size 比较特别的是 Flexibl ...

  2. 吴裕雄 数据挖掘与分析案例实战(5)——python数据可视化

    # 饼图的绘制# 导入第三方模块import matplotlibimport matplotlib.pyplot as plt plt.rcParams['font.sans-serif']=['S ...

  3. MapReduce超时原因(Time out after 300 secs)

    目前碰到过三种原因导致 Time out after 300 secs. 1. 死循环 这是最常见的原因.显式的死循环很容易定位,隐式的死循环就比较麻烦了,比如正则表达式.曾经用一个网上抄来的邮箱正则 ...

  4. 大型运输行业实战_day04_2_高级查询

    1.高级查询最总效果 2.高级查询步骤 2.1页面输入框显示 开始车站:<input id="startStation" type="text" valu ...

  5. Android自定义实现微信标题栏

    Android自定义实现微信标题栏     前言:在android的开发中有时我们需要更个性化的标题栏,而不仅仅是系统预定义的图标加软件名,同时有时候我们需要在标题栏中实现更多功能,如添加按钮响应用户 ...

  6. svn: authentication cancelled

    从svn 下程序时用户名和密码输入正确后报如图错误! 控制台输出: svn: authentication cancelled    svn: authentication cancelled    ...

  7. scanf与printf

    scanf格式控制的完整格式: %     *     m     l或h     格式字符 ①格式字符与printf函数中的使用方式相同,以%d.%o.%x.%c.%s.%f.%e,无%u格式.%g ...

  8. Spring Boot中使用Websocket搭建即时聊天系统

    1.首先在pom文件中引入Webscoekt的依赖 <!-- websocket依赖 --> <dependency> <groupId>org.springfra ...

  9. tmpFile.renameTo(classFile) failed解决

    完整异常: 严重: Servlet.service() for servlet [bjbr] in context with path [/HerPeisWechat] threw exception ...

  10. windows系统如何真正隐藏文件夹[转载]

    方法一(推荐)eg:现需隐藏e盘bak目录下的tools文件夹e:\bak\tools运行:cmd键入:attrib +s +a +h +r e:\bak\tools然后,你再进去看e盘bak目录下, ...