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. 错误处理try catch

    <?phpfunction inverse($x) { if (!$x) { throw new Exception('被除数不能为0'); } if ($x>31) { throw ne ...

  2. QML基础(六篇文章)

    http://www.cnblogs.com/hicjiajia/category/350988.html

  3. 基于visual Studio2013解决C语言竞赛题之0505选数

     题目

  4. 利用cmake来搭建开发环境

    对于经常在终端下写程序的non-windows程序员,Makefile绝对是最常用的工具,小到一个文件的简单的测试程序,大到数百个文件的商业软件,只需要有shell,一个make命令就可得到可运行的程 ...

  5. 《音乐商店》第4集:自动生成StoreManager控制器

    一.自动生成StoreManager控制器 二.查看 StoreManager 控制器的代码 现在,Store Manager 控制器中已经包含了一定数量的代码,我们从头到尾重新过一下. 1.访问数据 ...

  6. MYSQL中delete删除多表数据与删除关联数据

    在mysql中删除数据方法有很多种,最常用的是使用delete来删除记录,下面我来介绍delete删除单条记 录与删除多表关联数据的一些简单实例. 1.delete from t1 where 条件 ...

  7. 清华集训2014 day2 task1 简单回路

    题目 如题. 算法 就是刚学习的插头DP. 从前往后和从后往前分别进行一次DP. 要点 合法的括号序列只有103个 如何合并两次dp的信息 一开始犯傻了,以为当且仅当两个轮廓线的状态相同才是合法的方案 ...

  8. 关于java的环境变量的一点总结

    配置java环境变量: 一:为了在任意目录下使用java的开发工具javac,所以将javac.exe所在的目录加入到系统路径下, 即:在环境变量的path中加入javac.exe所在的目录.一般放在 ...

  9. JDBC连接SQL server与ADO.NET连接Sql Server对比

    JDBC连接SQL server与ADO.NET连接Sql Server对比 1.JDBC连接SQL server 1)java方面目前有很多驱动能够驱动连接SQL servernet.   主流的有 ...

  10. android 从其他app接收分享的内容

    Receiving Content from Other Apps[从其他app接收分享的内容] 就像你的程序能够发送数据到其他程序一样,其他程序也能够简单的接收发送过来的数据.需要考虑的是用户与你的 ...