UVa 1593 (水题 STL) Alignment of Code
话说STL的I/O流用的还真不多,就着这道题熟练一下。
用了两个新函数:
cout << std::setw(width[j]); 这个是设置输出宽度的,但是默认是在右侧补充空格
所以就要用cout.setf(ios::left);来设置一下左对齐。
#include <iostream>
#include <cstdio>
#include <sstream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
using namespace std; const int maxn = + ;
int width[maxn];
vector<string> a[maxn]; int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout); string line, s;
int cnt = ;
while(getline(cin, line))
{
stringstream ss(line);
while(ss >> s) a[cnt].push_back(s);
cnt++;
} int col = ;
for(int i = ; i < cnt; i++) { int t = a[i].size(); col = max(col, t); }
for(int i = ; i < col; i++)
{
for(int j = ; j < cnt; j++) if(i < a[j].size())
{
int t = a[j][i].length() + ;
width[i] = max(width[i], t);
}
}
width[col - ]--;
cout.setf(ios::left); //左对齐
for(int i = ; i < cnt; i++)
{
for(int j = ; j < col && j < a[i].size(); j++)
{
if(j == a[i].size() - ) cout << std::setw(a[i][j].length());
else cout << std::setw(width[j]);
cout << a[i][j];
}
puts("");
} return ;
}
代码君
UVa 1593 (水题 STL) Alignment of Code的更多相关文章
- UVa 10391 (水题 STL) Compound Words
今天下午略感无聊啊,切点水题打发打发时间,=_=|| 把所有字符串插入到一个set中去,然后对于每个字符串S,枚举所有可能的拆分组合S = A + B,看看A和B是否都在set中,是的话说明S就是一个 ...
- UVa 1595 (水题) Symmetry
颓废的一个下午,一直在切水题,(ˉ▽ ̄-) 首先如果这些点是对称的话,那么它们的对称轴就是x = m,m是横坐标的平均值. 把这些点放到一个集合里,然后扫描每个点,计算出它关于x = m的对称点,看这 ...
- UVa 10935 (水题) Throwing cards away I
直接用STL里的queue模拟即可. #include <cstdio> #include <queue> using namespace std; ; int discard ...
- UVa 400 (水题) Unix ls
题意: 有n个文件名,排序后按列优先左对齐输出.设最长的文件名的长度为M,则最后一列长度为M,其他列长度为M+2. 分析: 这道题很简单,但要把代码写的精炼,还是要好好考虑一下的.lrj的代码中有两个 ...
- UVa 11040 (水题) Add bricks in the wall
题意: 45块石头如图排列,每块石头上的数等于下面支撑它的两数之和,求其余未表示的数. 分析: 首先来计算最下面一行的数,A71 = A81 + A82 = A91 + 2A92 + A93,变形得到 ...
- UPC OJ 一道水题 STL
Problem C: 字符串游戏 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 10 Solved: 3 [Submit][Status][Web ...
- Square Numbers UVA - 11461(水题)
#include <iostream> #include <cstdio> #include <sstream> #include <cstring> ...
- CODE FESTIVAL 2017 qual B B - Problem Set【水题,stl map】
CODE FESTIVAL 2017 qual B B - Problem Set 确实水题,但当时没想到map,用sort后逐个比较解决的,感觉麻烦些,虽然效率高很多.map确实好写点. 用map: ...
- UVa 489 HangmanJudge --- 水题
UVa 489 题目大意:计算机给定一个单词让你猜,你猜一个字母,若单词中存在你猜测的字母,则会显示出来,否则算出错, 你最多只能出错7次(第6次错还能继续猜,第7次错就算你失败),另注意猜一个已经猜 ...
随机推荐
- request 获取请求参数
/** * 根据request获取请求的用户参数 * @return * @return */ protected <T> T getParamConvertEntity(Class cl ...
- adb或appium下多设备中指定设备的启动
一.先用adb devices列出所有设备序列号 List of devices attached012BDC7N78954789 device132AEC8N57897458 device 二.进入 ...
- POJ 1411
#include<iostream> #include<stdio.h> #include<math.h> #define MAXN 50000 using nam ...
- HDU 1869 六度分离
六度分离 http://acm.hdu.edu.cn/showproblem.php?pid=1869 Problem Description 1967年,美国著名的社会学家斯坦利·米尔格兰姆提出了一 ...
- JMeter监控服务器CPU, 内存,网络数据
http://wenku.baidu.com/link?url=un5QtWHa-A9kCTeVN0PnU3gDEMri38hYqjc8-skNXTD-v65FMObdq1LxfQDb1I6oIK9k ...
- Android安卓开发环境搭建详细教程
安装目录:步骤1 安装JDK步骤2 安装 Android SDK ----http://www.androiddevtools.cn/ 步骤3 安装Tomcat步骤4 安装Ant步骤5 安装Eclip ...
- sublime 支持PHP语法提示
下载插件phpcs>> https://github.com/benmatselby/sublime-phpcs 解压后修改文件夹名字为:Phpcs 把文件夹放到packages目录下 c ...
- Gray code---hdu5375(格雷码与二进制码,普通dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5375 题意就是:给你一串二进制码,里面可能含有'?'这个既可以表示0又可以表示1, 让我们把这个二进制 ...
- 蓝缘管理系统第三版推出。springMVC4.0+shiro1.2.3+spring4.x+Mybaits3.2.8
blog.csdn.net/mmm333zzz/article/details/42059349 http://blog.csdn.net/zoutongyuan/article/details/41 ...
- SPOJ 370 Ones and zeros BFS + 同余剪枝
题意:给一些n,求出最小的只包含0,1的n的倍数 设两数a, b满足: a < b 并且a % n = b % n. 如果 ( a * 10^x + c ) % n = z , 根据同余定理,( ...