Uva - 1593 - Alignment of Code
2015-06-12 22:31
369 查看
直接用<iomanip>的格式输出,setw设置输出宽度,setiosflags(ios::left)进行左对齐。
AC代码:
#include <iostream> #include <cstdio> #include <cstdlib> #include <cctype> #include <cstring> #include <string> #include <sstream> #include <vector> #include <set> #include <map> #include <algorithm> #include <stack> #include <queue> #include <iomanip> using namespace std; vector<string> s[1005]; int len[185]; int main() { string line, buf; int i = 0, j = 0; while (getline(cin, line)) { istringstream stream(line); while (stream >> buf) { len[j] = max(len[j], (int)buf.length()); j++; s[i].push_back(buf); } i++; j = 0; } // 设置左对齐 cout << setiosflags(ios::left); for (int k = 0; k < i; k++) { int l = 0; for (l; l < s[k].size() - 1; l++) { // setw设置宽度 cout << setw(len[l] + 1) << s[k][l]; } cout << s[k][l] << endl; } return 0; }
相关文章推荐
- Uva - 1593 - Alignment of Code
- 如何通过InstallShield打包应用程序
- Spring MVC 在JSP中获取service层的Bean对象
- UV镜 不镀膜、单层镀膜和多层镀膜 , “暗中”测试 数码相机UV镜效果对比
- 如何计算时间复杂度
- 世界最小隐身人诞生,晚上隐形性能最佳
- JDBC中PreparedStatement接口提供的execute、executeQuery和executeUpdate之间的区别及用法
- 【编译原理龙书笔记】(二)一个简单的语法制导翻译器(仍未完成)
- 25条提高Visual Studio编码和调试效率的技巧
- SQL语句 我喜欢上海
- c++ 用类模版实现链表(c++语言程序设计第四版示例代码)
- 给出复数,实现复数的四则运算
- 项目总结
- leetcod - Merge k Sorted Lists
- Mysql存储过程
- 第十一课:分离各位数|分离整数和小数部分|如何买玫瑰|玩数字|坐标转换
- 关于javascript的几个小实验
- Struts2运行流程、上传下载
- 网上查到关于innodb自增锁的详细完整的讲解--感觉不错
- LAMP环境搭建4-整合