直接用<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. JSON.parse(),JSON.stringify(),jQuery.parseJSON()

    http://www.jb51.net/article/29893.htm http://www.jb51.net/article/87642.htm

  2. Go 实现字符串相似度计算函数 Levenshtein 和 SimilarText

    [转]http://www.syyong.com/Go/Go-implements-the-string-similarity-calculation-function-Levenshtein-and ...

  3. jquery easyui combox不能编辑只能选择

    $('#tts').combobox({ editable:false });

  4. WEB中间件--Jboss未授权访问,

    1,Jboss未授权访问部署木马 发现存在Jboss默认页面,点进控制页 点击 Jboss.deployment 进入应用部署页面 也可以直接输入此URL进入 http://www.ctfswiki. ...

  5. css3部分整理

    1.css弹性盒子属性 父级元素属性的设置 #father{ width: 800px; height: 300px; background-color: darkgray; /*定义父级元素为弹性元 ...

  6. 位运算n & (n-1)的妙用

    本文转自:http://blog.csdn.net/zheng0518/article/details/8882394 按位与的知识 n&(n-1)作用:将n的二进制表示中的最低位为1的改为0 ...

  7. HTTP与TCP的关系

    一直比较想写TCP与HTTP之间的关系,HTTP报文是如何通过tcp发送的,HTTP报文形式内容如何. HTTP请求包含请求行,请求头,请求体 HTTP响应包含响应头,响应头,响应体 下面我准备通过J ...

  8. Go 语言递归函数

    递归,就是在运行的过程中调用自己. 语法格式如下: func recursion() { recursion() /* 函数调用自身 */ } func main() { recursion() } ...

  9. OC基础之推荐一个旋转木马(跑马灯)效果的图片展示Demo

    这个旋转木马(跑马灯)效果的图片展示Demo,包括设定旋转方向,图片倒影,背景设置,旋转速度,开始结束,点击显示选中的图片,彩色的块展示等等功能 效果图:(源码下载:https://github.co ...

  10. DrawerLayout案例

    布局文件: <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget ...