B. Center Alignment

题目连接:

http://www.codeforces.com/contest/5/problem/B

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

Sample Output


  • This is *
  •      *

Codeforces

  • Beta *
  • Round *
  • 5    *

Hint

题意

给你一堆字符串,让你居中

如果恰好居中的话,那就居中

如果不是的话,先偏左边,然后再偏右边去

题解:

模拟题,按照题意模拟就好了。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 2005;
string s[maxn],s1;
int mx,tot;
int main()
{
while(getline(cin,s1))
{
s[tot++]=s1;
mx = max((int)s1.size(),mx);
}
for(int i=0;i<mx+2;i++)
cout<<"*";
cout<<endl;
int d = 0;
for(int i=0;i<tot;i++)
{
cout<<"*";
int len = (mx-s[i].size());
if(len%2==1)d++;
int l = len/2;
int r = len/2;
if(len%2==1&&d%2==1)r++;
else if(len%2==1)l++;
for(int j=0;j<l;j++)cout<<" ";
cout<<s[i];
for(int j=0;j<r;j++)cout<<" ";
cout<<"*"<<endl;
}
for(int i=0;i<mx+2;i++)
cout<<"*";
cout<<endl;
}

Codeforces Beta Round #5 B. Center Alignment 模拟题的更多相关文章

  1. Codeforces Beta Round #7 B. Memory Manager 模拟题

    B. Memory Manager 题目连接: http://www.codeforces.com/contest/7/problem/B Description There is little ti ...

  2. Codeforces Beta Round #51 A. Flea travel 水题

    A. Flea travel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/problem ...

  3. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  4. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

  5. Codeforces Beta Round #74 (Div. 2 Only)

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

  6. Codeforces Beta Round #73 (Div. 2 Only)

    Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...

  7. Codeforces Beta Round #72 (Div. 2 Only)

    Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...

  8. Codeforces Beta Round #67 (Div. 2)

    Codeforces Beta Round #67 (Div. 2) http://codeforces.com/contest/75 A #include<bits/stdc++.h> ...

  9. Codeforces Beta Round #65 (Div. 2)

    Codeforces Beta Round #65 (Div. 2) http://codeforces.com/contest/71 A #include<bits/stdc++.h> ...

随机推荐

  1. Jsoup爬取带登录验证码的网站

    今天学完爬虫之后想的爬一下我们学校的教务系统,可是发现登录的时候有验证码.因此研究了Jsoup爬取带验证码的网站: 大体的思路是:(需要注意的是__VIEWSTATE一直变化,所以我们每个页面都需要重 ...

  2. (3)剑指Offer之数值的整数次方和调整数组元素顺序

    一 数值的整数次方 题目描述: 给定一个double类型的浮点数base和int类型的整数exponent.求base的exponent次方. 问题解析: 这道题算是比较麻烦和难一点的一个了.我这里采 ...

  3. Linux内核同步原语之原子操作【转】

    转自:http://blog.csdn.net/npy_lp/article/details/7262388 避免对同一数据的并发访问(通常由中断.对称多处理器.内核抢占等引起)称为同步. ——题记 ...

  4. 15个你不得不知道的Chrome dev tools的小技巧

    转载自:https://www.imooc.com/article/2559 谷歌浏览器如今是Web开发者们所使用的最流行的网页浏览器.伴随每六个星期一次的发布周期和不断扩大的强大的开发功能,Chro ...

  5. juery给所有ID属性相同的div绑定一个事件

    案例: <div id="div1">内容</div> <div id="div1">内容</div> < ...

  6. Android 开发笔记(一) 按钮事件调用Activity

    UI创建按钮及事件 Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button);mEmailSignInB ...

  7. fullpage.js 具体使用方法

    1.fullpage.js  下载地址 https://github.com/alvarotrigo/fullPage.js 2.fullPage.js 是一个基于 jQuery 的插件,它能够很方便 ...

  8. Dubbo使用

    [注:本文参考<Dubbo入门---搭建一个最简单的Demo框架>,感谢原创作者的知识探索与奉献] 一.Dubbo背景和简介 Dubbo开始于电商系统,因此在这里先从电商系统的演变讲起.  ...

  9. ECharts图表tooltip显示时超出canvas图层解决方法

    我们在做ECharts图表的时候可能会遇到tooltip显示时超出了canvas图层范围,并且被其它z-index较高的div容器遮盖,这是悬浮展示信息就看不全,我们根据官网文档的配置项查询发现con ...

  10. ASP.NET Core 2.0 MVC 发布部署--------- ASP.NET Core 发布的具体操作

    ASP.NET Core 发布的具体操作 下面使用C# 编写的ASP.NET Core Web项目示例说明发布的全过程. 1.创建项目 选择“文件” > “新建” > “项目”. 在“添加 ...