You are working in a team that writes Incredibly Customizable Programming Codewriter (ICPC) which is basically a text editor with bells and whistles. You are working on a module that takes a piece of code containing some definitions or other tabular information and aligns each column on a fixed vertical position, while keeping the resulting code as short as possible, making sure that only whitespaces that are absolutely required stay in the code. So, that the first words on each line are printed at position p1 = 1; the second words on each line are printed at the minimal possible position p2, such that all first words end at or before position p2 - 2; the third words on each line are printed at the minimal possible position p3, such that all second words end at or before position p3 - 2, etc.

For the purpose of this problem, the code consists of multiple lines. Each line consists of one or more words separated by spaces. Each word can contain uppercase and lowercase Latin letters, all ASCII punctuation marks, separators, and other non-whitespace ASCII characters (ASCII codes 33 to 126 inclusive). Whitespace consists of space characters (ASCII code 32).

Input

The input file contains one or more lines of the code up to the end of file. All lines (including the last one) are terminated by a standard end-of-line sequence in the file. Each line contains at least one word, each word is 1 to 80 characters long (inclusive). Words are separated by one or more spaces. Lines of the code can have both leading and trailing spaces. Each line in the input file is at most 180 characters long. There are at most 1000 lines in the input file.

Output

Write to the output file the reformatted, aligned code that consists of the same number of lines, with the same words in the same order, without trailing and leading spaces, separated by one or more spaces such that i-th word on each line starts at the same position pi.

Note for the Sample:

The `' character in the example below denotes a space character in the actual files (ASCII code 32).

Sample Input

  start:  integer;    // begins here
stop: integer; // ends here
s: string;
c: char; // temp

Sample Output

start: integer; // begins here
stop: integer; // ends here
s: string;
c: char; // temp
 
    #include <bits/stdc++.h>
using namespace std;
const int N = 1005, M = 200;
string s[N][M], line;
int cw[M], cn[N]; int main()
{
int r = 0, c = 0;
while(getline(cin, line))
{
stringstream ss(line);
while(ss >> s[r][c])
{
if(s[r][c].length() > cw[c])
cw[c] = s[r][c].length();
++c;
}
cn[r++] = c;
c = 0;
} for(int i = 0; i < r; ++i)
{
for(int j = 0; j < cn[i] - 1; ++j)
cout << left << setw(cw[j] + 1) << s[i][j];
cout << s[i][cn[i] - 1] << endl;
}
return 0;
}

  

A - Alignment of Code(推荐)的更多相关文章

  1. [刷题]算法竞赛入门经典(第2版) 5-1/UVa1593 - Alignment of Code

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) //UVa1593 - Alignment of Code #include&l ...

  2. Vs Code推荐安装插件

    前言: Visual Studio Code是一个轻量级但功能强大的源代码编辑器,轻量级指的是下载下来的Vs Code其实就是一个简单的编辑器,强大指的是支持多种语言的环境插件拓展,也正是因为这种支持 ...

  3. poj 3959 Alignment of Code <vector>“字符串”

    Description You are working in a team that writes Incredibly Customizable Programming Codewriter (IC ...

  4. VS code 推荐插件

    vs code 中eslint语法检测,保存即可格式化 具体查看:(https://www.jianshu.com/p/23a5d6194a4b) { // vscode默认启用了根据文件类型自动设置 ...

  5. UVA 1593 Alignment of Code(紫书习题5-1 字符串流)

    You are working in a team that writes Incredibly Customizable Programming Codewriter (ICPC) which is ...

  6. Alignment of Code UVA - 1593

      You are working in a team that writes Incredibly Customizable Programming Codewriter (ICPC) which ...

  7. UVa 1593 (水题 STL) Alignment of Code

    话说STL的I/O流用的还真不多,就着这道题熟练一下. 用了两个新函数: cout << std::setw(width[j]);    这个是设置输出宽度的,但是默认是在右侧补充空格 所 ...

  8. Uva - 1593 - Alignment of Code

    直接用<iomanip>的格式输出,setw设置输出宽度,setiosflags(ios::left)进行左对齐. AC代码: #include <iostream> #inc ...

  9. 代码对齐 (Alignment of Code,ACM/ICPC NEERC 2010,UVa1593)

    题目描述: 解题思路: 输入时提出单个字符串,并用一个数组记录每列最长长度,格式化输出 #include <iostream> #include <algorithm> #in ...

随机推荐

  1. vs2010如何打开vs2013

    vs2010如何打开vs2013 百度经验有,简单实用.

  2. QQ与我联系

    第一种 <a href=" http://sighttp.qq.com/cgi-bin/check?sigkey=ee8bdb91c04a9ae912a305a5a2461a0d8d6 ...

  3. 树莓派常用Linux命令

    转自小五义 1.ls命令:列出文件目录的常用命令,主要参数见下表. -a 列出目录下的所有文件,包括以.开头的隐含文件. -b 把文件名中不可输出的字符用反斜杠加字符编号(就象在C语言里一样)的形式列 ...

  4. Krita 3.0 发布,KOffice 的图像处理器(刺激一下自己的神经)

    Krita 3.0 发布了,经历了一年多的开发,动画功能被集成到Krita核心,改善了绘画功能,可及时预览绘画结果,该版本也是最新移植到QT的版本. 查看完整发布说明,可以点击这里. 下载地址: Wi ...

  5. Datagridview列绑定数据

    属性最下面的Column项: 把每一列的字段绑定,更改显示的标题. 数据绑定代码: string sql = "select IncomeExpendTypeID , TypeName , ...

  6. BZOJ 1260: [CQOI2007]涂色paint( 区间dp )

    区间dp.. dp( l , r ) 表示让 [ l , r ] 这个区间都变成目标颜色的最少涂色次数. 考虑转移 : l == r 则 dp( l , r ) = 1 ( 显然 ) s[ l ] = ...

  7. structure and interpretation of Computer programs -- Foreword

    Foreword  前言 Educators, generals, dieticians, psychologists, and parents program.   Armies, students ...

  8. Handler.removeMessages的作用,有时候为什么一定要先remove一下呢

    removeMessages会将handler对应message queue里的消息清空,如果带了int参数则是对应的消息清空.队列里面没有消息则handler会不工作,但不表示handler会停止. ...

  9. php 使用curl发起https请求

    今天一个同事反映,使用curl发起https请求的时候报错:“SSL certificate problem, verify that the CA cert is OK. Details: erro ...

  10. linux登录windows服务器

    在公司同时也兼顾了王老师会议网站的任务,我喜欢用linux,而会议网站托管在windows系统上,虽然装了双系统,但我还是比较懒,不喜欢经常切换系统.还好,linux可以实现登录windows服务器. ...