直接用<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. mysql 合并left join 数据条目

    查询两张关联表信息,原sql: SELECT * FROM  car_life_info c left JOIN shop_label sl ON  c.shop_id = sl.shop_id 出现 ...

  2. selenium登录163邮箱

    环境:windows8  python2.7+selenium+chrome 直接上脚本: # coding=utf-8from selenium import webdriverimport tim ...

  3. Genymotion配置遇到的坑

    1.Genymotion 无法Add下来 解决: ①首先打开Genymotion,的Settings然后找到VirtualBox,复制链接,在本地找到文件夹,然后返回上一层找到ova文件夹进入, ②然 ...

  4. redis的基本数据类型

    一:redis是一个开源的,使用C语言编写,支持网络,可基于内存亦可持久化的日志型,key-value方式存储的nosql数据库.作为缓存服务器,速度效率都很快,和memcache相似 redis支持 ...

  5. Ubuntu 下安装 matlab2018a

    如果存在依赖关系无法安装,可以尝试命令:sudo apt --fix-broken install 不指明软件包而解决此问题. 参考资料:Ubuntu 16.04LTS 安装 MATLAB 2014B ...

  6. JavaScript原型与原型链

    一.数据类型 JavaScript的数据类型可以分为基本数据类型和引用数据类型. 基本数据类型(6种) String Number Boolean null undefined Symbol(ES6) ...

  7. 分别用face++和百度获取人脸属性(python单机版)

    称之为单机版,主要是相对于调用摄像头实时识别而言.本篇主要py2下利用face++和百度接口获取本地图片中的人脸属性,并按照一定格式保存数据. face++版 face++是刚注册的,只能用一个试用的 ...

  8. Activity的四种启动模式任务栈图解

    转载本专栏文章,请注明出处,尊重原创 .文章博客地址:道龙的博客 今天带来另一篇Activity的文章--Activity的四种启动模式.该篇文章,会以图文讲解的方式带你彻底掌握Activity的启动 ...

  9. Vue 踩坑记

    参考: https://forum.vuejs.org/t/unknown-issues-in-change-event-of-radio-in-vue-2-x-webpack-2-x/11034 v ...

  10. docker iotop :OSError: Netlink error: No such file or directory

    在容器内使用iotop ,错误信息: raceback (most recent call last): File "/usr/sbin/iotop", line 16, in & ...