CF_5B_CenterAlignment
来源:互联网 发布:c语言 字符串统计函数 编辑:程序博客网 时间:2024/05/29 16:24
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!
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.
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.
This isCodeforcesBetaRound5
************* This is ** **Codeforces** Beta ** Round ** 5 *************
welcome to theCodeforcesBetaRound 5andgood luck
*****************welcome to the** Codeforces ** Beta ** Round 5 ** ** and ** good luck *****************
题意给给定的字符块
加一个框子,并给每行居中
不能完全居中的先左一格后右一格 交替
#include <iostream>#include <stdio.h>#include <string.h>using namespace std;const int M=1005;char s[M][M];int sl[M];int main(){ int num=0; int msl=0;//最大串长度 int lr=1; //记录下次向左向右 //freopen("1.in","r",stdin); while(gets(s[num])!=NULL) { sl[num]=strlen(s[num]); msl=max(msl,sl[num]); num++; } for(int i=1;i<=msl+2;i++) //上框 printf("*"); printf("\n"); for(int i=0;i<num;i++) { printf("*"); if((msl-sl[i])&1) { if(lr) { for(int j=0;j<(msl-sl[i])/2;j++) printf(" "); printf("%s",s[i]); for(int j=0;j<=(msl-sl[i])/2;j++) printf(" "); } else { for(int j=0;j<=(msl-sl[i])/2;j++) printf(" "); printf("%s",s[i]); for(int j=0;j<(msl-sl[i])/2;j++) printf(" "); } lr=1-lr; } else { for(int j=0;j<(msl-sl[i])/2;j++) printf(" "); printf("%s",s[i]); for(int j=0;j<(msl-sl[i])/2;j++) printf(" "); } printf("*\n"); } for(int i=1;i<=msl+2;i++) //下框 printf("*"); printf("\n"); return 0;}
- CF_5B_CenterAlignment
- swift基础2
- 功能强大的Xcode辅助工具Faux Pas:帮你找到各种隐形的bug
- 26、Java调用Oracle存储过程?
- USB Mass Storage大容量存储的基本知识
- UINavigationController ( 导航控制器 )
- CF_5B_CenterAlignment
- [Unity官方文档翻译]Importing Assets 如何向unity导入资源
- BZOJ 1086([SCOI2005]王室联邦-树的划分)
- ios swift 归档解档遇到的坑 3-30
- ubuntu 15.04 通过3306端口远程连接mysql
- C++组合应用之strtok字符串分割、数组平分算法、动态数组函数传参
- android手机安全性测试手段
- PCL系列——从深度图像(RangeImage)中提取NARF关键点
- 【poj 1159】 Palindrome DP(类最长公共子序列)+滚动数组