Uva - 1593 - Alignment of Code
直接用<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的更多相关文章
- UVA 1593 Alignment of Code(紫书习题5-1 字符串流)
You are working in a team that writes Incredibly Customizable Programming Codewriter (ICPC) which is ...
- UVA 1593: Alignment of Code(模拟 Grade D)
题意: 格式化代码.每个单词对齐,至少隔开一个空格. 思路: 模拟.求出每个单词最大长度,然后按行输出. 代码: #include <cstdio> #include <cstdli ...
- [刷题]算法竞赛入门经典(第2版) 5-1/UVa1593 - Alignment of Code
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) //UVa1593 - Alignment of Code #include&l ...
- Alignment of Code UVA - 1593
You are working in a team that writes Incredibly Customizable Programming Codewriter (ICPC) which ...
- UVa 1593 (水题 STL) Alignment of Code
话说STL的I/O流用的还真不多,就着这道题熟练一下. 用了两个新函数: cout << std::setw(width[j]); 这个是设置输出宽度的,但是默认是在右侧补充空格 所 ...
- 【习题5-1 UVA - 1593】Alignment of Code
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟题,每一列都选最长的那个字符串,然后后面加一个空格就好. 这个作为场宽. 模拟输出就好. [代码] #include <b ...
- UVa 1593代码对齐
原题链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- poj 3959 Alignment of Code <vector>“字符串”
Description You are working in a team that writes Incredibly Customizable Programming Codewriter (IC ...
- A - Alignment of Code(推荐)
You are working in a team that writes Incredibly Customizable Programming Codewriter (ICPC) which is ...
随机推荐
- Linux允许、禁止ping包
默认情况下Linux系统允许ping,但是在某些情况下为了安全起见,我们都把服务器设置为禁ping 临时允许ping命令可使用命令: echo 0 >/proc/sys/net/ipv4/ic ...
- java判断A字符串是否包含B字符串
public static void main(String[] args) { String str="ABC_001"; if(str.indexOf("ABC&qu ...
- dataview findrows
DataView dvStu = dsStu.Tables[0].Copy().DefaultView;//当前学年学期下所有学生 dvStu.Sort = "bjmc,xm"; ...
- HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917)
IE8报错误: 用户代理: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .N ...
- spring的事务配置方法
spring事务的配置有两种方式 1.xml配置的声明式事务配置 (1)配置数据源信息dataSource(使用阿里的数据源) <bean id="dataSource" c ...
- 深入浅出低功耗蓝牙(BLE)协议栈
深入浅出低功耗蓝牙(BLE)协议栈 BLE协议栈为什么要分层?怎么理解蓝牙"连接"?如果蓝牙协议只有ATT没有GATT会发生什么? 协议栈框架 一般而言,我们把某个协议的实现代码称 ...
- Docker仓库
仓库是集中存放镜像文件的场所.有时候会把仓库和仓库注册服务器(Registry)混为一谈,并不严格区分.实际上,仓库注册服务器上往往存放着多个仓库,每个仓库中又包含了多个镜像,每个镜像有不同的标签(t ...
- RxJava操作符(09-算术/聚合操作&连接操作)
转载请标明出处: http://blog.csdn.net/xmxkf/article/details/51692493 本文出自:[openXu的博客] 目录: 算术聚合 Count Concat ...
- [OpenCV]在显示窗口中截图
[OpenCV]在显示窗口中截图 简介 介绍使用OpenCV实现简单的截图功能.首先阐述实现此功能的基本步骤,然后给出实现代码,最后贴出实验结果以及遇到的问题. 基本步骤 我们需要知道OpenCV使用 ...
- shell编程--流程控制for,do-while,if-then,break,continue,case等
2.5 流程控制 2.5.1 if语法 1.语法格式 if condition then statements [elif condition then statements. ..] ...