直接用<iomanip>的格式输出,setw设置输出宽度,setiosflags(ios::left)进行左对齐。

AC代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
#include <iomanip> 

using namespace std;

vector<string> s[1005];
int len[185];

int main()
{
	string line, buf;
	int i = 0, j = 0;
	while (getline(cin, line)) {
		istringstream stream(line);
		while (stream >> buf) {
			len[j] = max(len[j], (int)buf.length());
			j++;
			s[i].push_back(buf);
		}
		i++;
		j = 0;
	}
	// 设置左对齐
	cout << setiosflags(ios::left);
	for (int k = 0; k < i; k++) {
		int l = 0;
		for (l; l < s[k].size() - 1; l++) {
			// setw设置宽度
			cout << setw(len[l] + 1) << s[k][l];
		}
		cout << s[k][l] << endl;
	}

	return 0;
}

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

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

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

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

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

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

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

  4. Alignment of Code UVA - 1593

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

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

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

  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. Java的数组排序

    对数组进行排序 使用到的排序算法有: 1 选择排序   2 冒泡排序   3 插入排序    4 JavaAPI提高排序算法 选择排序的原理: 1 将数组中每个元素与第一个元素比较,如果这个元素小于第 ...

  2. html下载excel模板

    只需要href等于模板存放的路径即可 <a href="../../TempLate/Attitude.xlsx" class="easyui-linkbutton ...

  3. consul怎么在windows下安装

    1.去官网下载:https://www.consul.io/downloads.html 2.解压: 3.设置环境变量:path添加 E:\programfiles\consul: 4.cmd启动: ...

  4. Asp.Net Core 2.0 项目实战(7)MD5加密、AES&DES对称加解密

    本文目录 1. 摘要 2. MD5加密封装 3. AES的加密.解密 4. DES加密/解密 5. 总结 1.  摘要 C#中常用的一些加密和解密方案,如:md5加密.RSA加密与解密和DES加密等, ...

  5. js改变dom对象样式

    object.style.display = value; objcet对象必须是确定单个对象. 若以class名和标签名查找,需要指定对象集合中的第几个.

  6. Django笔记--模型

    ORM是"对象-关系-映射"的简称,在Django当中,ORM就是模型类的管理器对象.操作顺序是先定义模型类,再定义模型类管理器,然后在模型类中实例化一个模型类管理器的对象,作为模 ...

  7. Python小代码_2_格式化输出

    Python小代码_2_格式化输出 name = input("name:") age = input("age:") job = input("jo ...

  8. vue-cli中配置sass

    第一步, npm install node-sass --save-dev npm install sass-loader --save-dev 第二部,打开webpack.base.config.j ...

  9. SpringMVC之Ajax与Controller交互

    前面学习了拦截器,通过拦截器我们可以拦截请求,做进一步处理之后再往下进行,这里我们使用Ajax的时候会有一个问题就是会把js.css这些静态资源文件也进行了拦截,这样在jsp中就无法引入的静态资源文件 ...

  10. Bootstrap3 表格-状态类

    通过这些状态类可以为行或单元格设置颜色. .active---鼠标悬停在行或单元格上时所设置的颜色 .success--–标识成功或积极的动作 .info----标识普通的提示信息或动作 .warni ...