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的更多相关文章
随机推荐
- java 1.7
http://superuser.com/questions/740064/how-to-install-java-1-7-runtime-on-macos-10-9-mavericks sudo r ...
- ecshop之transport和jquery冲突之完美解决方案
众所周知:ecshop的transport.js文件和Jquery是冲突的,两个文件不能同时调用,现给出以下完美解决方案:原因分析:在transport.js文件中,大概 580行到590行之间,这个 ...
- Bootstarp: sub_menu 自定义改变nav样式
<style> .nav > li > a { position: relative; display: block; padding: 5px 5px; } </sty ...
- Mac os装软件时提示显示需要安装旧Java SE 6运行环境解决办法
这个时Java版本的问题,换用合适的低版本即可,下面是官方的 https://support.apple.com/kb/DL1572?viewlocale=zh_CN&locale=en_US ...
- Effective Java 学习笔记之所有对象都通用的方法
一.覆盖equals时请遵守通用约定 1.满足下列任何一个条件时,不需要覆盖equals方法 a.类的每个实例本质上都是唯一的.此时就是Object中equals方法所表达的含义. b.不关心类是否提 ...
- Reflow(渲染)和Repaint(重绘)
Reflow(渲染):对于DOM结构中的各个元素都有自己的盒模型,浏览器根据各种样式(浏览器的.开发人员定义的等)来计算,并根据计算结果将元素放到它该出现的位置,这个过程称之为reflow. refl ...
- NSTimer用法,暂停,继续,初始化
NSTimer用法,暂停,继续,初始化 转载:http://blog.csdn.net/zhuzhihai1988/article/details/7742881 NSTimer的使用方法 1.初始化 ...
- html5跨域通讯之postMessage的用法
转自:http://www.cnblogs.com/wshiqtb/p/3171199.html postMessagePortal.html 页面代码 <!DOCTYPE html> & ...
- 可复用View的PagerAdapter
用PagerAdapter的时候会反复调用instantiateItem和destroyItem来创建和销毁View,没有复用性.这里封装了一个可复用View的PagerAdapter,给实现类留下的 ...
- html5——canvas画直线
<html> <head> <title>canvas demo</title> </head> <body> <canv ...