NEFU要崛起——第4场 B - Center Alignment
来源:互联网 发布:影梭 本地端口 编辑:程序博客网 时间:2024/04/29 09:27
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 isCodeforcesBetaRound5
************* This is ** **Codeforces** Beta ** Round ** 5 *************
welcome to theCodeforcesBetaRound 5andgood luck
*****************welcome to the** Codeforces ** Beta ** Round 5 ** ** and ** good luck *****************
题意:看看输入输出就明白了 输出个框框~ 我懂得
代码:
#include<cstdio>#include<cstring>#include<iostream>using namespace std;const int mm=1111;char s[mm][mm];int i,n,m,ml,w,a,b;void outc(int m,char c){ while(m--)printf("%c",c);}int main(){ n=0; while(gets(s[n]))++n; for(ml=i=0;i<n;++i) ml=max(ml,(int)strlen(s[i])); outc(ml+2,'*'); puts(""); for(w=i=0;i<n;++i) { printf("*"); m=ml-strlen(s[i]); a=m/2; if(m&1)a+=w,w=w^1; b=m-a; outc(a,' '); printf("%s",s[i]); outc(b,' '); printf("*\n"); } outc(ml+2,'*'); puts(""); return 0;}
来自Pira 's source code
- NEFU要崛起——第4场 B - Center Alignment
- NEFU要崛起——第4场
- codeforces--NEFU要崛起——第1场 " B - Winne
- NEFU要崛起——第3场 B - Before an Exam
- NEFU要崛起——第5场 B - President's Office
- NEFU要崛起——第1场
- NEFU要崛起——第2场
- NEFU要崛起——第3场
- NEFU要崛起——第3场 A - Watermelon
- NEFU要崛起——第5场
- NEFU要崛起——第6场
- NEFU要崛起——第7场
- NEFU要崛起——第3场 A - Watermelon
- NEFU要崛起——第8场
- NEFU要崛起——第9场
- NEFU要崛起——第10场
- NEFU要崛起——第11~15场
- NEFU要崛起——第16场 A - Triangle
- 关于ASP.NET页面与代码分离
- 分散信用管理
- CCS中使用DSP定时器的计时程序,可以精确计算某一段程序的执行时间
- 销售订单抬头与行项目数据的关系
- .Net处理json数据常见的几种方法
- NEFU要崛起——第4场 B - Center Alignment
- WebService CXF学习(入门篇4):整合Spring框架
- IACCESSIBLE
- php常用调试工具
- PHP 压缩字符串方法
- 安卓(android)即时通讯
- C#中的深复制和浅复制(在C#中克隆对象)
- valgrind 安装
- 云计算权威的入门书籍