看上去十分麻烦的一道题,但是看了看别人的写法感觉大神们写的无比简单。

就是记一个每列单词的最大长度,然后剩下的事交给NB的iomanip头文件就好。

stringsteam是一个神奇的东西。

#include <iostream>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <string>
#include <cstring>
#include <vector> using namespace std;
#define maxn 1000 + 100 vector<string> code[maxn];
int maxlen[maxn]; int main()
{
string s;
int cas = 0;
while (getline(cin, s))
{
stringstream ss(s);//用这个字符串流可以从字符串中输入文件
string word;
int tot = 0;
while(ss >> word)
{
maxlen[tot] = max(maxlen[tot], (int)word.size());
code[cas].push_back(word);
++tot;
}
++cas;
} cout << setiosflags(ios :: left);
for (int j = 0; j < cas; j++)
{
int i = 0;
for (i; i < code[j].size()-1; i++)
cout << setw(maxlen[i] + 1) << code[j][i]; cout << code[j][i] << endl;
} }

UVa - 1593 代码对齐(STL)的更多相关文章

  1. UVa 1593代码对齐

    原题链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  2. UVa 1593 (水题 STL) Alignment of Code

    话说STL的I/O流用的还真不多,就着这道题熟练一下. 用了两个新函数: cout << std::setw(width[j]);    这个是设置输出宽度的,但是默认是在右侧补充空格 所 ...

  3. UVa第五章STL应用 习题((解题报告))具体!

    例题5--9 数据库 Database UVa 1592 #include<iostream> #include<stdio.h> #include<string.h&g ...

  4. vs code代码对齐快捷键

    vscode缩进快捷键: 选中文本: Ctrl  +  [      和   Ctrl  +  ]     实现文本的向左移动或者向右移动: vscode代码对齐快捷键: 选中文本: Shift  + ...

  5. VS中代码对齐等快捷键

    在VS2008中,选定代码后,按Ctrl+K+F组合键,可以自动进行代码对齐. 注意:要先按下Ctrl和K,再按下F,因为Ctrl+F是查找的快捷键. 也可以先按下Ctrl+K,再按下Ctrl+F. ...

  6. vs快捷键代码格式化或代码对齐名字

    开发人员,换个电脑后环境要重装,vs的环境也需要重新设置. 快捷键需要重新设置,插件也需要重装,在这里备注下,换个环境就可以直接用了. 由于vs不同版本,代码对齐或者代码格式化的快捷键都不一样,所以导 ...

  7. UVA 1593 Alignment of Code(紫书习题5-1 字符串流)

    You are working in a team that writes Incredibly Customizable Programming Codewriter (ICPC) which is ...

  8. vim中编辑了代码 但是提示can not write的解决办法和代码对齐办法

    方式1: 1 :w /tmp/xxxx(如果是c文件就.c拉)  保存在/tmp下面 2 从tmp中复制到有权限的目录下面 cp /tmp xxxx ./(当前目录) 方式2::w !sudo tee ...

  9. multiple-cursors做代码对齐

    multiple-cursors做代码对齐 */--> code {color: #FF0000} pre.src {background-color: #002b36; color: #839 ...

随机推荐

  1. centOS6.5 安装后无法启动无线上网

    查看无线网卡型号:[root@mookee rtl8192se_linux_2.6.0019.1207.2010]# lspci |grep Network03:00.0 Network contro ...

  2. 程序运行过程中遇到“ORA-03114: not connected to ORACLE”的问题解决

    c#,winform程序,数据批量入oracle库时用到DataAdaper的.FillSchema函数,如:da.FillSchema(dt2, SchemaType.Mapped); 程序运行一段 ...

  3. 故障案例:主从同步报错Fatal error: The slave I/O thread stops because master and slave have equal MySQL server

    https://blog.csdn.net/cug_jiang126com/article/details/46846031

  4. [luogu 1967]货车运输

    货车运输 题目描述 A 国有 n 座城市,编号从 1 到 n,城市之间有 m 条双向道路.每一条道路对车辆都有重量限制,简称限重.现在有 q 辆货车在运输货物, 司机们想知道每辆车在不超过车辆限重的情 ...

  5. 洛谷 P1203 [USACO1.1]坏掉的项链Broken Necklace

    坏掉的项链Broken Necklace 难度:★ Code: #include <iostream> #include <cstdio> #include <cstri ...

  6. C++ error:Debug Assertion Failed.Expression:_BLOCK_TYPE_IS_VALID(phead->nBlock)

    Debug Assertion Failed.Expression:_BLOCK_TYPE_IS_VALID(phead->nBlockUse) 关于上面这个错误,我在上一篇文章中的程序遇到过了 ...

  7. 变更gcc版本

    当前的GCC版本为GCC-4.2,需要切换到GCC-3.4.首先,你需要去你的usr/bin/下去看看有没有gcc-3.4这样文件,如果没有的话,就安装一下吧: apt-get install gcc ...

  8. RSA加密解密(转)

    RSA加密解密 对于RSA产生的公钥.私钥,我们可以有两种方式可以对信息进行加密解密.私钥加密-公钥解密 和 公钥加密-私钥解密RSA公钥加密算法是1977年由罗纳德·李维斯特(Ron Rivest) ...

  9. Leet-code144. Binary Tree Preorder Traversal

    这是一道将二叉树先序遍历,题目不难. 首先采用深搜递归 /** * Definition for a binary tree node. * public class TreeNode { * int ...

  10. IIS 7.0的根文件(applicationHost.config)位置及说明

    位置 C:\Windows\System32\inetsrv\config\applicationHost.config 说明 https://www.microsoft.com/taiwan/tec ...