/练习输入输出
#include <bits/stdc++.h>using namespace std;
void print(string str, int len)
{if(str.length()==0)return;cout << str;for(int i=0;i<=len-str.length();i++)printf(" ");
}
const int maxn = 1005;
int tot[maxn][100];//tot 记录每行所有单词长度
int main()
{vector<string> line[maxn];string str;int row=0,cnt[maxn];//cnt 记录每行单词数memset(cnt,0,sizeof(cnt));memset(tot,0,sizeof(tot));while(getline(cin,str)){stringstream ss(str);string x;while(ss >> x){tot[row][cnt[row]]=x.length();cnt[row]++;line[row].push_back(x);}row++;}int maxcol[90];memset(maxcol,0,sizeof(maxcol));for(int i=0;i<=row;i++)for(int j=0;j<cnt[i];j++)if(maxcol[j]<tot[i][j])maxcol[j]=tot[i][j];for(int i=0;i<=row;i++){for(int j=0;j<cnt[i];j++){if(j==cnt[i]-1){cout << line[i][j] << "\n";break;}print(line[i][j],maxcol[j]);}}}

原题如下:

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 code32).
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

UVa 1593 Alignment of code 解题报告相关推荐

  1. UVA 1593 Alignment of Code

    题意: 输入后对齐输出. 思路: ①用一个vector数组装每行的字符. ②用整型数组len存每列最大的长度加一(多算一个空格),比如在样例输入中,第一列最大的是start:. 1 #include& ...

  2. 28行代码AC——习题3-12 浮点数(UVA 11809 - Floating-Point Numbers)——解题报告

    励志用少的代码做高效的表达 题目(提交)链接→UVA-11809 算是个数学题吧,虽然在AOAPC上面给放到象征水题的第三章里面了. 这个题基本就是帮着你复习了一遍浮点数的存储方式了.浮点数在计算机里 ...

  3. 解题报告(五)组合计数(ACM / OI)超高质量题解

    繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量题解和代码,题目难度不一定按照题号排序,我会在每道题后面加上题目难度指数(1∼51 \sim 51∼5),以模板题难度 11 ...

  4. 解题报告(十八)数论题目泛做(Codeforces 难度:2000 ~ 3000 + )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量的题解和代码,题目难度不一 ...

  5. 解题报告(三)多项式求值与插值(拉格朗日插值)(ACM / OI)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量的题解和代码,题目难度不一 ...

  6. 解题报告(十三)中国剩余定理(ACM / OI)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量的题解和代码,题目难度不一 ...

  7. 解题报告(四)生成函数(ACM/ OI)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量的题解和代码,题目难度不一 ...

  8. 解题报告(八) prufer 序列与 Cayley 公式(ACM / OI)超高质量题解

    繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量题解和代码,题目难度不一定按照题号排序,我会在每道题后面加上题目难度指数(1∼51 \sim 51∼5),以模板题难度 11 ...

  9. 解题报告(一)E、(BZOJ4589)Hard Nim(博弈论 + FWT)

    繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量题解和代码,题目难度不一定按照题号排序,我会在每道题后面加上题目难度指数(1∼51 \sim 51∼5),以模板题难度 11 ...

最新文章

  1. 菜鸡记录-王爽-汇编语言-实验十(编写子程序-显示字符串)
  2. 简单介绍python连接telnet和ssh的两种方式
  3. 如何使用RecyclerView构建Horizo​​ntal ListView?
  4. zabbix邮件报警python脚本
  5. FreeMarker 自动转义和格式化HTML和XML输出,预防xss
  6. oracleDBA-D1
  7. 腾讯游戏应邀2019大数据产业峰会BDIC | 荣获“大数据星河奖”并获颁测评证书...
  8. ETL数据处理后的业务分析(一)
  9. 关于Integer大小比较的问题
  10. SPH(光滑粒子流体动力学)流体模拟实现四:各向异性(Anisotropic)表面光滑(2)
  11. 一篇文章搞定java序列化机制
  12. 网络是怎样连接的-IP与以太网的包收发操作(三)
  13. 电蚊拍GB4706检测及安规测试设备
  14. CHM格式打不开解决方案
  15. Matlab 统计不同元素个数
  16. 九招使用 Telegram必学,使用Telegram 必看实用功能
  17. HDU 5055 Bob and math problem(构造)
  18. 如何度过生活的低谷?
  19. 计算机图形学(二)输出图元_19_显示窗口重定形函数
  20. linux fetion

热门文章

  1. 如何将当前时间转换为YYYY-MM-DD HH:MM:SS
  2. 【python】QQ登录接口分析
  3. 对日开发-详细设计的经验
  4. 合并两个有序单链表,使得合并后的链表仍然有序
  5. 浅谈MacBook Pro 2019 15寸
  6. bno055传感器数据不更新_Bosch BNO055 应用特定型传感器节点实现智能化 9 轴绝对方向感应...
  7. C语言头文件互锁和包含问题
  8. 【收藏】国外知名地球物理研究小组
  9. 二手车小程序制作及相关问题介绍
  10. java-springboot计算机毕业设计基于安卓Android的二手车查询平台APP