UVA 1593 Alignment of Code 注意格式问题。。以及可以用stringstream解决但是我没用
来源:互联网 发布:人类不会毁于人工智能 编辑:程序博客网 时间:2024/06/03 04:02
好吧,按照刘汝佳书上的说法,stringstream超级慢。。。。所以不想去用,但是老实说感觉用stringstream挺方便的,想了一想,sscanf也不是很好用,结果用了string,以及自己手写。
用了一个vector<string>,以及还有一些格式输出的问题,setw格式化,以及ios里面的位开关,还有读题的重要性。。不能有前缀后缀空格,总之在思维难度上比DP还是要简单很多。。。。放手去写就好了,一下是代码。
#include <string>#include <iostream>#include <vector>#include <iterator>#include <cctype>#include <cstring>#include <iomanip>using namespace std;vector<string> v[1005];size_t words,num[1005],le,ri,line;string str;int main(){ ios_base::sync_with_stdio(false); cout.setf(ios::left); while(getline(cin,str)){ for(le=ri=0;ri<str.size();){ if(le==ri&&str[ri]==' ') ++le,++ri; else if(le==ri&&isgraph(str[ri])) ++ri; else if(str[ri]==' ') v[line].push_back(string(str.begin()+le,str.begin()+ri)),le=ri; else if(isgraph(str[ri])) ++ri; } if(le<str.size()&&isgraph(str[le])) v[line].push_back(string(str.begin()+le,str.begin()+ri)); ++line; } for(int i=0;i<line;++i) words=max(words,v[i].size()); for(int i=0;i<line;++i) for(int j=v[i].size()-1;j>=0;--j) num[j]=max(num[j],v[i][j].size()); for(int i=0;i<line;++i){ for(int j=1;j<v[i].size()-1;++j) cout<<setw(num[j]+1)<<v[i][j]; cout<<v[i].back()<<endl; } return 0;}
0 0
- UVA 1593 Alignment of Code 注意格式问题。。以及可以用stringstream解决但是我没用
- UVa 1593 - Alignment of Code(格式+细节)
- UVa 1593 Alignment of Code
- UVa 1593 - Alignment of Code
- UVa 1593 - Alignment of Code
- UVa 1593 Alignment of Code
- Uva - 1593 - Alignment of Code
- UVA 1593 Alignment of Code
- UVa 1593 - Alignment of Code
- UVA 1593 Alignment of Code
- UVa 1593 Alignment of Code
- uva 1593 Alignment of Code
- UVA 1593 Alignment of Code
- Uva Alignment of Code
- Alignment of Code UVA
- Alignment of Code UVA
- UVa 1593 Alignment of Code(字符串)
- UVa--1593 Alignment of Code(string)
- Android 基于百度语音的语音交互功能
- 【LeetCode】410. Split Array Largest Sum
- 打印numpy数组全部内容
- [LeetCode 108] Convert Sorted Array to Binary Search Tree
- O(1)时间内删除单向链表中的一个节点
- UVA 1593 Alignment of Code 注意格式问题。。以及可以用stringstream解决但是我没用
- BZOJ 2506: calc【离线,值域分块
- python3.5.2下安装BeautifuSoup--bs4
- BROWSEINFO用法
- 这是测试
- ViewPager 详解(四)----自主实现滑动指示条
- Web前端优化常用规则
- 20161114
- 如何自学Android