UVa1593_Allgnment_Of_Code

时间:2022-08-28 00:19:09
 /**
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的更多相关文章

    随机推荐

    1. 安装arbotix simulator仿真环境--9

      原创博客:转载请表明出处:http://www.cnblogs.com/zxouxuewei/  周学伟 安装之前:首先确保已经正常制作了ros工作空间并且安装了rbx1功能包: cd ~/catki ...

    2. Mongodb集群搭建及spring和java连接配置记录

      一.基本环境: mongdb3.0.5数据库 spring-data-mongodb-1.7.2.jar mongo-java-driver-3.0.2.jar linux-redhat6.3 tom ...

    3. 【学习笔记】【C语言】逗号运算符

      逗号运算符主要用于连接表达式,例如: int a = 9; int b = 10; a = a+1 , b = 3*4; * 用逗号运算符连接起来的表达式称为逗号表达式,它的一般形式为: 表达式1, ...

    4. HDU-2527 Safe Or Unsafe

      http://acm.hdu.edu.cn/showproblem.php?pid=2527 建哈夫曼树,哈夫曼编码,求wpl值. Safe Or Unsafe Time Limit: 2000/10 ...

    5. 【LeetCode练习题】Multiply Strings

      Multiply Strings Given two numbers represented as strings, return multiplication of the numbers as a ...

    6. AngularJS高级程序设计读书笔记 -- 模块篇

      一. 模块基础 1. 创建模块 <!DOCTYPE html> <html ng-app="exampleApp"> <head> <ti ...

    7. MyBatis之基于XML的动态SQL

      先说下我的梦想,大学的时候一直想着是能开店卖胡辣汤,到目前依然还是我的梦想,上周一家出版社联系我问我有没有时间可以合作出书,这也是我的梦想之一,想了想还是放弃了,至少觉得目前不行,毕竟工作还不到五年, ...

    8. WSGI协议主要包括server和application两部分:

      WSGI server负责从客户端接收请求,将request转发给application,将application返回的response返回给客户端:WSGI application接收由server ...

    9. BZOJ&period;2324&period;&lbrack;ZJOI2011&rsqb;营救皮卡丘&lpar;费用流 Floyd&rpar;

      BZOJ 洛谷 首先预处理出\(dis[i][j]\),表示从\(i\)到\(j\)的最短路.可以用\(Floyd\)处理. 注意\(i,j\)是没有大小关系限制的(\(i>j\)的\(dis[ ...

    10. linux Ubuntu系统安装百度aip

      1.下载百度api pip install baidu-aip 2.配置视频转码工具ffmpeg Ubuntu16.04下安装FFmpeg(超简单版) 第一步:添加源. sudo add-apt-re ...