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> ...
随机推荐
- http介绍
1.http特点: 1>简单快捷: 2>灵活: 3>支持客户端.服务器结构: 4>无连接----无连接的含义是限制每次连接只处理一个请求: 5>无状态----无状态是指协 ...
- WPF拖动DataGrid滚动条时内容混乱的解决方法
WPF拖动DataGrid滚动条时内容混乱的解决方法 在WPF中,如果DataGrid里使用了模板列,当拖动滚动条时,往往会出现列表内容显示混乱的情况.解决方法就是在Binding的时候给Update ...
- Windows搭建RobotFramework环境(一)
Robot Framework官网 http://robotframework.org/http://robotframework.org/ 安装说明 https://github.com/robot ...
- selenium grid应用1-多浏览器执行用例
driver =webdriver.Remote(command_executor=’http://127.0.0.1:4444/wd/hub’, desired_capabilities=Desir ...
- str.format() 格式化字符串函数
语法 它通过{}和:来代替%. “映射”示例 通过位置 In [1]: '{0},{1}'.format('kzc',18) Out[1]: 'kzc,18' In [2]: '{},{}'.form ...
- java.lang.IllegalArgumentException: Page directive: invalid value for import
我的项目原来用的tomcat版本是apache-tomcat-7.0.53,后来为了安全原因将版本升至\apache-tomcat-7.0.57,发现有的jsp页面出现下面的异常: java.lang ...
- shell之read命令
一.概述 read命令接收标准输入(键盘)的输入,或者其他文件描述符的输入.得到输入后,read命令将数据放入一个标准变量中. 二.使用举例(这里仅列出一些常用的选项) 1.基本读取 #!/bin/b ...
- bind1st bind2nd的使用
STL中的函数 bind1st. bind2nd用于将一个二元算子转换成一元算子,需要两个 参数,要转换的bf和一个值v. 参考:http://blog.csdn.net/simahao/articl ...
- MyBatis3-与Spring MVC 4集成
继前一篇的例子http://www.cnblogs.com/EasonJim/p/7052388.html,已经集成了Spring框架,现在将改造成Spring MVC的项目,并实现如下功能: 1.不 ...
- python_xlsxwriter模块
1.workbook类 add_worksheet 用于添加一个新的工作表,sheetname为工作表名称,默认是sheet1,例如: worksheet = workbook.add_workshe ...