首页 > 其他 > 详细

Uva 400.Unix is

时间:2016-02-27 06:19:55      阅读:346      评论:0      收藏:0      [点我收藏+]

怎么看这道题都是理解比实现难

特别是英语版,最后如何输出被绕进去了

大概意思就是在保证每行不超过60字符的情况下,尽可能让行数最少输出。

注意三目运算符的运算优先度,记得加括号

 

 1 #include <cstdio>
 2 #include <string>
 3 #include <cstring>
 4 #include <iostream>
 5 #include <vector>
 6 #include <algorithm>
 7 using namespace std;
 8 
 9 class LOVE{
10     private:
11         static const int len=65;
12         static const int maxn=105;
13 
14     public:
15         bool Do(){
16             int n,Max=0;
17             if(!(cin>>n))
18                 return false;
19             cout<<"------------------------------------------------------------\n";
20             string str[maxn];
21             for(int i=0;i<n;i++){
22                 cin>>str[i];
23                 Max=max(Max,(int)str[i].size());
24             }
25             sort(str,str+n);
26 
27             int L,H;
28             for(int i=n;i>0;i--){
29                 L=i;
30                 H=n/L+(n%L?1:0);
31                 int size=Max*L+2*(L-1);
32                 if(size<=60)break;
33             }
34             //cout<<"\n"<<L<<" "<<H<<"\n";
35             for(int i=0;i<H;i++){
36                 for(int j=0;j<L;j++){
37                     cout<<str[i+j*H];
38                     for(int k=0;k<(j==L-1?0:2)+Max-(int)str[i+j*H].size();k++)
39                         cout<<" ";
40                 }
41                 cout<<"\n";
42             }
43             return true;
44         }
45 };
46 
47 int main(){
48     //freopen("in.txt","r",stdin);
49     std::ios::sync_with_stdio(false);
50     LOVE LIVE;
51     while(LIVE.Do());
52     return 0;
53 }

 

Uva 400.Unix is

原文:http://www.cnblogs.com/ohyee/p/5222207.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!