uva 400 - Unix ls
2013-12-26 21:48
447 查看
这题其实很简单,但是re了很多次,因为天真到用setw,以及cout<<left来控制输出格式,改成手动后就ac了
#include<iostream> #include<string> #include<stdio.h> #include<iomanip> #include<vector> #include<stdlib.h> #include<algorithm> using namespace std; int main(){ int n; vector<string> words; while(cin>>n){ getchar(); string l; int max=0; for(int i=0;i<n;i++){ getline(cin,l); if(max<l.size()) max=l.size(); words.push_back(l); } sort(words.begin(),words.end()); cout<<"------------------------------------------------------------"<<endl; int columnnum=(60-max)/(max+2)+1; int rownum=(n%columnnum>0)?(n/columnnum+1):(n/columnnum); for(int i=0;i<rownum;i++){ for(int j=0;j<columnnum;j++){ if(i+j*rownum>=n) break; cout<<words[i+j*rownum]; for(int k=words[i+j*rownum].size();k<((j==columnnum)?(max):(max+2));k++){ cout<<" "; } } cout<<endl; } words.clear(); } }
相关文章推荐
- UVA - 400 Unix ls
- Unix ls UVA - 400
- 【例题5-8 UVA - 400】Unix ls
- UVa-400 Unix ls
- UVa——400Unix ls(字典序文本处理输出iomanip)
- 算法竞赛入门经典第五章例题5-8 Unix ls UVA - 400
- UVA 400 Unix ls by sixleaves
- UVa 400 - Unix ls
- UVa 400 - Unix ls
- UVa 400 Unix ls 命令
- Unix ls, UVa 400
- uva400 unix ls (字符串 排序)
- Uva - 400 - Unix ls
- UVA 400 Unix ls
- Uva - 400 - Unix ls
- Unix ls UVA400
- 例题5-8 Unix ls 命令 UVa400
- uva 400 Unix ls 文件输出排版 排序题
- UVa 400 - Unix ls
- uva 400 - Unix ls