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

HINT

题目的解决思路很清晰,就是录入和输出。录入的方式采用的是读取整行然后赋给stringstream对单词进行分段。分段的该过程中要对每一列的最大长度进行计算。输出就按照正常输出就行,然后后面计算空格的个数。

注意:每一行最后一个单词后面直接换行,不要输出空格!!!

Accepted

#include<iostream>
#include<vector>
#include<cstring>
#include <algorithm>
#include<queue>
#include<sstream>
using namespace std;
int main()
{
queue<string>str[1010];
int maxlen[200] = { 0 };
char arr[200] = { 0 };
memset(arr, ' ', 200);
int num = 0;
string s;
char ss[200];
while (cin.getline(ss,200))
{
int i = 0;
stringstream sss(ss);
while (sss >> s)
{
str[num].push(s);
if (s.length() > maxlen[i++])maxlen[i-1] = s.length();
}
num++;
}
for (int i = 0;i < num;i++)
{
int j = 0;
while (!str[i].empty())
{
cout << str[i].front();
if (str[i].size() != 1)
{
arr[maxlen[j] - str[i].front().length()] = '\0';
cout << arr;
arr[maxlen[j++] - str[i].front().length()] = ' ';
}
str[i].pop();
if (str[i].size())cout << " ";
else {
cout << endl;break;
}
}
}
}

Alignment of Code UVA - 1593的更多相关文章

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

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

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

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

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

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

  4. Uva - 1593 - Alignment of Code

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

  5. UVA 1593: Alignment of Code(模拟 Grade D)

    题意: 格式化代码.每个单词对齐,至少隔开一个空格. 思路: 模拟.求出每个单词最大长度,然后按行输出. 代码: #include <cstdio> #include <cstdli ...

  6. 【习题5-1 UVA - 1593】Alignment of Code

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟题,每一列都选最长的那个字符串,然后后面加一个空格就好. 这个作为场宽. 模拟输出就好. [代码] #include <b ...

  7. UVa 1593代码对齐

    原题链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

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

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

  9. A - Alignment of Code(推荐)

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

随机推荐

  1. Jmeter beanshell编程实例

    1.引言 BeanShell是一种小型的,免费的,可嵌入的符合Java语法规范的源代码解释器,具有对象脚本语言特性. 在Jmeter实践中,由于BeanShell组件较高的自由度,通常被用来处理较为复 ...

  2. 「TcaplusDB知识库」概念(表、键、记录、索引)

       TcaplusDB作为一款NoSQL数据库,语法与传统的SQL关系库有所差异.本文将详细介绍TcaplusDB表.记录.索引这三个数据库中常用术语在TcaplusDB中的概念与意义. 术语\概念 ...

  3. C++ Primer Plus 第一章 预备知识

    C++ Primer Plus 第一章 预备知识 知识点梳理 本章主要讲述了C++的由来,讨论了面向过程语言与面向对象语言的区别,介绍了ANSI/ISO制定的C++标准,阐述了在Windows.Mac ...

  4. 【ZeyFraのJavaEE开发小知识01】@DateTimeFomat和@JsonFormat

    @DateTimeFormat 所在包:org.springframework.format.annotation.DateTimeFormat springframework的注解,一般用来对Dat ...

  5. 学习java之基础语法(一)

    学习java之基础语法(一) 基本语法 编写 Java 程序时,应注意以下几点: 大小写敏感:Java 是大小写敏感的,这就意味着标识符 Hello 与 hello 是不同的. 类名:对于所有的类来说 ...

  6. FFT HDL Optimized模块HDL综合代码生成及与Xilinx xfft IP MEX接口精度详细比较

    前面一篇随笔叙述了关于MATLAB中FFT_HDL_Optimzed模块定点(IEEE754单精度float格式)二进制与十进制转换实现,有需要的往前翻一下即可.这一篇随笔将叙述 FFT HDL Op ...

  7. 那些你不知道的DOU+投放技巧,以及常见的审核失败原因丨国仁网络

    作为小额付费投放工具,DOU+一直深受各大中小商家的青睐.虽然它的审核比较严格,但转化效果还是非常明显的. 近日,抖音发布重要公告:内容低质的视频将无法购买DOU+推广,并可能因违反平台规则导致无法观 ...

  8. 每日一题20201112(922. 按奇偶排序数组 II)

    题目链接: 922. 按奇偶排序数组 II 思路 很简单,搞懂问题的核心就行,假设现在有奇数在偶数位上,偶数在奇数位上. 那么我们要做的就是,找到分别在对方位置上的数字,然后交换他们就行. class ...

  9. 死磕Spring之IoC篇 - @Autowired 等注解的实现原理

    该系列文章是本人在学习 Spring 的过程中总结下来的,里面涉及到相关源码,可能对读者不太友好,请结合我的源码注释 Spring 源码分析 GitHub 地址 进行阅读 Spring 版本:5.1. ...

  10. jdk 集合大家族之Map

    jdk 集合大家族之Map 前言: 之前章节复习了Collection接口相关,此次我们来一起回顾一下Map相关 .本文基于jdk1.8. 1. HashMap 1.1 概述 HashMap相对于Li ...