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> ...
随机推荐
- 阿里分布式开源框架DUBBO 入门+ 进阶+ 项目实战视频教程
史诗级Java/JavaWeb学习资源免费分享 欢迎关注我的微信公众号:"Java面试通关手册"(坚持原创,分享各种Java学习资源,面试题,优质文章,以及企业级Java实战项目回 ...
- Linux CentOS 6.9(图形界面)安装中文输入法
安装步骤 1. 切换到 root 用户,执行 yum -y install "@Chinese Support" 2. 退出终端,选择桌面菜单中 "System" ...
- ubuntu的su初始密码设置
Ubuntu刚安装后,不能在terminal中运行su命令,因为root没有默认密码,需要手动设定. 以安装ubuntu时输入的用户名登陆,该用户在admin组中,有权限给root设定密码. 给roo ...
- 121.Best Time to Buy and Sell Stock---dp
题目链接:https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/ 题目大意:给出一串数组,找到差值最大的差 ...
- 关于"轉淚點"与"轉捩點"
经常看台湾偶像剧或台湾综艺节目的人,一定听过"转泪点"这个词,虽然我一直不知道这三个字具体是怎么写, 但其意思很容易明白,就是"转折点"的意思.今天无聊在看凤凰 ...
- 小甲鱼Python笔记(上)
基于Python 3.4.3 一 二 三 四 基础 print 三版必须加括号,二版不用加 alt + n :上一条语句 alt + p :下一条语句 打印三条hello 没有大括号,用缩进来表示 ...
- [实战]MVC5+EF6+MySql企业网盘实战(12)——新建文件夹和上传文件
写在前面 之前的上传文件的功能,只能上传到根目录,前两篇文章实现了新建文件夹的功能,则这里对上传文件的功能进行适配. 系列文章 [EF]vs15+ef6+mysql code first方式 [实战] ...
- vue 阻止事件冒泡
<mt-button type="danger" size="small" @click="cancelOrderInfo(this.even ...
- POJ 1597 Function Run Fun
记忆化搜索. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
- 洛谷P3758/BZOJ4887 [TJOI2017] 可乐 [矩阵快速幂]
洛谷传送门,BZOJ传送门 可乐 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 299 Solved: 207 Description 加里敦星球的人 ...