UVa1593_Allgnment_Of_Code
/**
start: integer; // begins hear
stop: integer; // ends here
s: string;
c: char; // temp
**/ //测试数据
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
using namespace std; vector<string> txt[];
string code, tmp;
int max_len[]; //储存每列最大的字符串长度 void print(const string& s, int len, char extra)
{
cout << s;
for (unsigned int i = ; i <= len-s.length(); i++)
cout << extra;
} int main()
{
int cols = , row = ; //列数, 行数
while (getline(cin, code))
{
istringstream ss(code); //istringstream从string对象中读取
while (ss >> tmp) {
max_len[cols] = max(max_len[cols], (int)tmp.size()); //求出每行的每列上的最大字符串长度
cols++; //列数++
txt[row].push_back(tmp);
}
row++; cols = ; //行数++, 列数归零
}
for (int i = ; i < row; i++)
{
unsigned int j = ;
for ( ; j < txt[i].size() - ; j++)
{
print(txt[i][j], max_len[j], ' '); //输出单个字符串,长度不够的输出空格
}
cout << txt[i][j] << endl; //每行每列
}
return ;
}
这里有一篇关于:istringstream, ostringstream, stringstream的文章,感觉不错.
http://www.cnblogs.com/gamesky/archive/2013/01/09/2852356.html
UVa1593_Allgnment_Of_Code的更多相关文章
随机推荐
- Mac Pro 修改主机名
修改 主机名称 sudo scutil --set HostName jianbao-PC 修改 共享名称 sudo scutil --set ComputerName jianbao-PC
- wp手机 htc x310e
入手htc x310e 手机不错,用着流畅 不习惯,已升到wp7.8,系统限制还是有些需要的功能没有,比如说短信拦截什么的 我需要的常用软件少 转手了 1 注销windows live? 设置--应用 ...
- leetcode150 Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...
- 表单select相关
selectedIndex 属性可设置或返回下拉列表中被选选项的索引号. options[] 返回包含下拉列表中的所有选项的一个数组. add()向下拉列表添加一个选项. blur()从下拉列表移开焦 ...
- 问题: Oracle Database 10g 未在当前操作系统中经过认证
问题: Oracle Database 10g 未在当前操作系统中经过认证 在Windows 7中安装Oracle 10g. 使用的Orcale版本是10g. 步骤1: 在Orcale官网上下载,下载 ...
- C++变量对比java变量所占内存
C++ char 1 short int 2 int 4 long int 8 float 4 double 8 long double 8 下面是计算程序: #include<math.h&g ...
- MATLAB命令大全
一.常用对象操作:除了一般windows窗口的常用功能键外.1.!dir 可以查看当前工作目录的文件. !dir& 可以在dos状态下查看.2.who 可以查看当前工作空间变量名, whos ...
- memcache 与 mencached扩展的区别
memcache是一套分布式的高速缓存系统,由LiveJournal的Brad Fitzpatrick开发,但目前被许多网站使用以提升网站的访问速度,尤其对于一些大型的.需要频繁访问数据库的网站访问速 ...
- C/C++相对论——C++中为什么要使用异常?
C++中为什么要使用异常? 很多人也许知道C++中的异常机制,很多人也许不知道.很多人知道C中常用的assert,也知道在编译时候指定NODEBUG来忽略它. 对于C语言,使用正常的if-else即是 ...
- 26 BasicUsageEnvironment基本使用环境——Live555源码阅读(三)UsageEnvironment
26 BasicUsageEnvironment基本使用环境--Live555源码阅读(三)UsageEnvironment 26 BasicUsageEnvironment基本使用环境--Live5 ...