【习题5-1 UVA - 1593】Alignment of Code
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
模拟题,每一列都选最长的那个字符串,然后后面加一个空格就好。
这个作为场宽。
模拟输出就好。
【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
const int M = 200;
string ss;
vector <string> s[N+10];
int pre[M],lie[M],start[M];
void out(int len, int used)
{
for (int j = 0; j < len - used; j++) putchar(' ');
}
int main()
{
//freopen("F:\\rush.txt", "r", stdin);
int row = 0;
while (getline(cin, ss))
{
stringstream ts(ss);
string temp;
while (ts >> temp) {
s[row].push_back(temp);
lie[(int)s[row].size() - 1] = max(lie[(int)s[row].size() - 1], (int)temp.size());
}
row++;
}
start[0] = 0;
for (int j = 1; j < M && lie[j] != 0; j++) start[j] = start[j-1] + lie[j - 1] + 1;
for (int i = 0; i < row; i++)
{
cout << s[i][0];
for (int j = 1; j < (int)s[i].size(); j++)
{
out(start[j]-start[j-1],(int)s[i][j-1].size());
cout << s[i][j];
}
cout << endl;
}
return 0;
}
【习题5-1 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
直接用<iomanip>的格式输出,setw设置输出宽度,setiosflags(ios::left)进行左对齐. AC代码: #include <iostream> #inc ...
- 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]); 这个是设置输出宽度的,但是默认是在右侧补充空格 所 ...
- 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 ...
随机推荐
- Rabin-Karp 算法
Rabin-Karp字符串查找算法 http://blog.chinaunix.net/uid-26548237-id-3968132.html
- JavaScript笔记(5)
1.return 跳出当前函数 返回一个结果 <script> //return可以跳出当前函数 所以return写在函数的最后一行 function out() { return fun ...
- 使用C库制作DLL
一.用C编写制作 DLL 如下图所示,是在C++的基础上新建的项目工程: 新建项目的工程文件中有.cpp文件. 由于我们是用C库制作的DLL,显然用C++来编写的是不合适的,我为什么用C库,而不用C+ ...
- 让JavaScript在Visual Studio 2015中编辑得更easy
微软公布的Visual Studio 2015展示了该公司对于让该开发工具更好的支持主流的开发语言的工作.微软项目经理Jordan Matthiesen已经具体列出了一些具体处理JavaScript开 ...
- actionmode-ActionMode以及它的menu使用
下图左边效果为Context Menu右边效果为ActionMode. ActionMode 其实就是替换在actionbar的位置上显示的一个控件.它跟actionbar一样,也是一种导航作用.只不 ...
- Linux在应用层读写寄存器的方法。。。
参考链接:http://blog.csdn.net/liukang325/article/details/26601811 /dev/mem:物理内存的全镜像.可以用来访问物理内存.由于应用运行都在用 ...
- Zabbix监控告警
一 钉钉告警 1.1.1 添加钉钉机器人 发起群聊 创建完群聊选择,机器人管理 选择你要绑定的群聊 复制下面地址留用 1.1.2 编写钉钉告警脚本 安装requests库,HTTP客户端, # yum ...
- 给VG增加磁盘,给文件目录增加空间
一: #lspv 找到新增加的物理卷(逻辑驱动器,以hdisk8为例). #chdev –l hdisk8 –a pv=yes写入新的物理卷的pvid. #extendvg cwdatavg hdis ...
- SpringCloud核心教程 | 第一篇: 使用Intellij中的Spring Initializr来快速构建Spring Cloud工程
spring cloud简介 spring cloud 为开发人员提供了快速构建分布式系统的一些工具,包括配置管理.服务发现.断路器.路由.微代理.事件总线.全局锁.决策竞选.分布式会话等等.它运行环 ...
- 洛谷 P1636 Einstein学画画
P1636 Einstein学画画 题目描述 Einstein学起了画画, 此人比较懒--,他希望用最少的笔画画出一张画... 给定一个无向图,包含n 个顶点(编号1~n),m 条边,求最少用多少笔可 ...