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 ...
随机推荐
- Python笔记(十一):多线程
(二)和(三)不感兴趣的可以跳过,这里参考了<深入理解计算机系统>第一章和<Python核心编程>第四章 (一) 多线程编程 一个程序包含多个子任务,并且子任务之间相 ...
- linux安装mysql数据库
安装mysql 1.下载MySQL的安装文件 安装MySQL需要下面两个文件: MySQL-server-4.0.23-0.i386.rpm MySQL-client-4.0.23-0.i386.rp ...
- Spring使用webjar
注意事项 这玩意很简单,但是我们第一次搞就是搞不成功,为什么呢?因为我们都用的是idea或者eclipse编译.webjar只能在maven上才能打包,所以在使用时,记得maven-clean和mav ...
- C语言多维数组的指针传递
在C语言中为了节省空间,提高运行速度经常使用指针来完成数组的传递. 对于一维数组而言可以直接传递首地址 而对于二维数组必须在传递时声明是二维数组的指针,并且调用时也要经过一些运算 首先是定义形参: 函 ...
- E1
en表"使怎么样" engage 吸引,从事,订婚 be engaged in doing sth. 忙于 endure 忍耐,忍受 enforce 强制执行 enrol ...
- admin的配置
当我们访问http://127.0.0.1:8080/admin/时,会出现: 执行命令: 生成同步数据库的脚本:python manage.py makemigrations ...
- CSDN博客投票活动开始了
自己坚持写博客,一方面是为了将自己对知识点的理解做一个总结,另一方面也是因为自己看到了很多无私奉献分享自己知识的小伙伴们,因此自己也想像他们那样尽自己微薄之力把自己对某一知识点的理解分享给大家,或许算 ...
- How To determine DDIC Check Table, Domain and Get Table Field Text Data For Value?
How To determineDDIC Check Table, Domain and Get Table Field Text Data For Value? 1.Get Table Fie ...
- DuKBitmapImages 图片压缩处理技术
Android图片压缩上传系列 *压缩中的问题: --图片压缩上如果存在问题,势必造成消耗大量的流量,下载图片的速度慢等影响产品性能,那么如何解决?请看下面: 压缩图片一共多少张?一起压缩?分开压缩? ...
- CNN在中文文本分类的应用
深度学习近一段时间以来在图像处理和NLP任务上都取得了不俗的成绩.通常,图像处理的任务是借助CNN来完成的,其特有的卷积.池化结构能够提取图像中各种不同程度的纹理.结构,并最终结合全连接网络实现信息的 ...