A - Alignment of Code(推荐)
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(推荐)的更多相关文章
- [刷题]算法竞赛入门经典(第2版) 5-1/UVa1593 - Alignment of Code
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) //UVa1593 - Alignment of Code #include&l ...
- Vs Code推荐安装插件
前言: Visual Studio Code是一个轻量级但功能强大的源代码编辑器,轻量级指的是下载下来的Vs Code其实就是一个简单的编辑器,强大指的是支持多种语言的环境插件拓展,也正是因为这种支持 ...
- poj 3959 Alignment of Code <vector>“字符串”
Description You are working in a team that writes Incredibly Customizable Programming Codewriter (IC ...
- VS code 推荐插件
vs code 中eslint语法检测,保存即可格式化 具体查看:(https://www.jianshu.com/p/23a5d6194a4b) { // vscode默认启用了根据文件类型自动设置 ...
- UVA 1593 Alignment of Code(紫书习题5-1 字符串流)
You are working in a team that writes Incredibly Customizable Programming Codewriter (ICPC) which is ...
- Alignment of Code UVA - 1593
You are working in a team that writes Incredibly Customizable Programming Codewriter (ICPC) which ...
- UVa 1593 (水题 STL) Alignment of Code
话说STL的I/O流用的还真不多,就着这道题熟练一下. 用了两个新函数: cout << std::setw(width[j]); 这个是设置输出宽度的,但是默认是在右侧补充空格 所 ...
- Uva - 1593 - Alignment of Code
直接用<iomanip>的格式输出,setw设置输出宽度,setiosflags(ios::left)进行左对齐. AC代码: #include <iostream> #inc ...
- 代码对齐 (Alignment of Code,ACM/ICPC NEERC 2010,UVa1593)
题目描述: 解题思路: 输入时提出单个字符串,并用一个数组记录每列最长长度,格式化输出 #include <iostream> #include <algorithm> #in ...
随机推荐
- Ajax,设置默认焦点以及判断是否为空
<style type="text/css"> .tishi{ color: red; } </style> <script type="t ...
- java基础之注解
包含成员变量及方法的注解称之为元数据, 不包含任何成员的注解称之为标记. 用@interface定义注解, 使用类似于接口方法的方式来定义注解的属性,其中返回值成为属性的类型,方法名为属性的名称. p ...
- 基于Sql Server 2008的分布式数据库的实践(四)
原文 基于Sql Server 2008的分布式数据库的实践(四) 数据库设计 1.E-R图 2.数据库创建 Win 7 1 create database V3 Win 2003 1 create ...
- yii_wiki_145_yii-cjuidialog-for-create-new-model (通过CJuiDialog来创建新的Model)
/**** CJuiDialog for create new model http://www.yiiframework.com/wiki/145/cjuidialog-for-create-new ...
- 利用JNI技术在Android中调用C++形式的OpenGL ES 2.0函数
1. 打开Eclipse,File-->New-->Project…-->Android-->AndroidApplication Projec ...
- 利用ant的javac任务来编译程序使用ant的java任务来运行程序
<?xml version="1.0" encoding="UTF-8"?> <project name="javaTest&quo ...
- 基于visual Studio2013解决算法导论之007优先队列(堆实现)
题目 优先队列 解决代码及点评 #include <stdio.h> #include <stdlib.h> #include <malloc.h> #in ...
- CString Format 乱码问题
CString m_buf;CStatic *m_static;char *szName;...m_buf.Format(":%s",szName);m_static->Se ...
- [poj 1265]Area[Pick定理][三角剖分]
题意: 给出机器人移动的向量, 计算包围区域的内部整点, 边上整点, 面积. 思路: 面积是用三角剖分, 边上整点与GCD有关, 内部整点套用Pick定理. S = I + E / 2 - 1 I 为 ...
- C# -- 什么是方法签名?
签名指的是返回值和参数. 比如 : public void A ( int p1,int p2){} public void B ( int q1,int q2){} 的签名相同. 而 public ...