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的更多相关文章
随机推荐
- 常用开源镜像站整理android sdk manager
http://www.cocoachina.com/programmer/20151023/13852.html http://android-mirror.bugly.qq.com:8080/inc ...
- 关于phpcms中mysql和mysqli的区别
用phpcms开发一个考试成绩查询的小模块,用电脑上以前下载的phpcms版本为框架开发,一切顺利.想着下载一个最新版本,以后也免了升级的麻烦.于是,下载好,然后把模块目录.model数据库连接文件. ...
- MongoDB的学习和使用
一.下载mongodb. 官网下载, 或者http://www.360sdn.com/opensource-datasource/2015/0403/5584.html下载: http://fastd ...
- Markdown入门教程
Markdown 是一种轻量级的「标记语言」,它的优点很多,目前也被越来越多的写作爱好者,撰稿者广泛使用.看到这里请不要被「标记」.「语言」所迷惑,Markdown 的语法十分简单.常用的标记符号也不 ...
- 剑指Offer 从上往下打印二叉树(dfs)
题目描述 从上往下打印出二叉树的每个节点,同层节点从左至右打印. 思路: 用一个队列来辅助,先压入根节点,设置一个指针记录队列头位置,判断队头指针有没有孩子,有压入左右孩子,,,操作完一次,队头出 ...
- peewee 字段属性help_text的支持问题
至少在__version__ = '2.6.0'的时候,给字段添加help_text的时候,在数据库的ddl语句里面是没有comment的. 看了下源码,顺藤摸瓜,最终定位到了字段(Field类)的_ ...
- C#基础语法实例荟萃
匿名类 action = new UploadHandler(context, new UploadConfig() { AllowExtensions = Config.GetStringList( ...
- rpm包制作(待实验)
作者:firefoxbug 时间:July 18, 2014 rpm包命名规范 对于rpm包的命名符合如下规范. %{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}.rpm N ...
- [20160704]Addition program that use JOptionPane for input and output
//Addition program that use JOptionPane for input and output. import javax.swing.JOptionPane; public ...
- Python之socket简介
http://goodcandle.cnblogs.com/archive/2005/12/10/294652.aspx http://yangrong.blog.51cto.com/6945369/ ...