Codeforces Beta Round #5 B. Center Alignment 模拟题
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 模拟题的更多相关文章
- Codeforces Beta Round #7 B. Memory Manager 模拟题
B. Memory Manager 题目连接: http://www.codeforces.com/contest/7/problem/B Description There is little ti ...
- Codeforces Beta Round #51 A. Flea travel 水题
A. Flea travel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/problem ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
- Codeforces Beta Round #73 (Div. 2 Only)
Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...
- Codeforces Beta Round #72 (Div. 2 Only)
Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...
- Codeforces Beta Round #67 (Div. 2)
Codeforces Beta Round #67 (Div. 2) http://codeforces.com/contest/75 A #include<bits/stdc++.h> ...
- Codeforces Beta Round #65 (Div. 2)
Codeforces Beta Round #65 (Div. 2) http://codeforces.com/contest/71 A #include<bits/stdc++.h> ...
随机推荐
- UML相关说明
在java开发中,有很多时候我们是在不断的处理类与类之间关系,其中这六种关系是:依赖.关联.聚合.组合.继承.实现. 它们的强弱关系是没有异议的:依赖 < 关联 < 聚合 < 组合& ...
- Neuroph studio 入门教程
PERCEPTRON Perceptron is a simple two layer neural network with several neurons in input layer, and ...
- CRF++模板使用(转)
CRF++模板构建分为两类,一类是Unigram标注,一类是Bigram标注. Unigram和Bigram模板分别生成CRF的状态特征函数 和转移特征函数 .其中 是标签, 是观测序列, ...
- Django 1.10文档中文版Part4
2.10 高级教程:如何编写可重用的apps 2.10.1 重用的概念 The Python Package Index (PyPI)有大量的现成可用的Python库.https://www.djan ...
- AspNet Core 发布到Linux系统和发布IIS 注意项
AspNet Core 发布到Linux系统和发布IIS 注意项 1.发布时需要注意的 2.Windows Server 2012 api-ms-win-crt-runtime-l1-1-0.dll ...
- Gradient-Based Learning Applied to Document Recognition 部分阅读
卷积网络 卷积网络用三种结构来确保移位.尺度和旋转不变:局部感知野.权值共享和时间或空间降采样.典型的leNet-5如下图所示: C1中每个特征图的每个单元和输入的25个点相连,这个5* ...
- Gitlab部署及汉化操作
一.简介 GitLab是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目. GitLab拥有与Github类似的功能 ...
- python基础(6)---set、collections介绍
1.set(集合) set和dict类似,也是一组key的集合,但不存储value.由于key不能重复,所以,在set中,没有重复的key. 集合和我们数学中集合的概念是一样的,也有交集.并集.差集. ...
- LeetCode818. Race Car
https://leetcode.com/problems/race-car/description/ Your car starts at position 0 and speed +1 on an ...
- jquery validate表单验证插件的基本使用方法及功能拓展
1 表单验证的准备工作 在开启长篇大论之前,首先将表单验证的效果展示给大家. 1.点击表单项,显示帮助提示 2.鼠标离开表单项时,开始校验元素 3.鼠标离开后的正确.错误提示及鼠标移入时的帮助提 ...