Fuzzy Time

FJNU.1269

Description
Kyle is downloading a moe. concert using BitTorrent. He notices that the time left is given as "2 hours 15 minutes." Later it becomes "0 minutes 37 seconds" and then finally finishes. Kyle thinks about it and decides that the program could easily say "8,101 seconds" to be precise, but that this isn't very useful. He wants you to write a program that, given a time in seconds, prints out a less precise, but more useful ("fuzzy") version.
The rules for fuzziness that Kyle wants implemented are:
.Any time longer than or equal to 48 hours, should be given in terms of the number of days.
.Between 1 hour(inclusive) and 48 hours, the program should display the number of hours and number of minutes left.
.Between 5 minutes and 59 minutes, 59 seconds, inclusive, the program should only display the number of minutes left.
.Less than 5 minutes should be displayed as the number of minutes and number of seconds left.
No rounding is to be done. Anything left over is simply dropped, so 365 and 419 would both be displayed as "6 minutes". Kyle would also like you to use proper plural forms.
While you're working on that, Kyle is going to go listen to the concert, which apparently has an amazing version of "Timmy Tucker" on it.

Input
Each line of input gives one time, in seconds, that you are to convert. Input is terminated by end of file.

Output
For each input, print out the fuzzy time version according to the rules Kyle gave you above.

Sample Input
0
65
365
419
7270
172800
300000

Sample Output
0 minutes 0 seconds
1 minute 5 seconds
6 minutes
6 minutes
2 hours 1 minute
2 days
3 days

My Program

#include < iostream >
#define  M 60
#define  H 3600
#define  D 86400
using   namespace  std;

int  main()
{
    
int n;
    
int d,h,m;
    
while(cin>>n)
    
{
        d
=n/D;
        n
%=D;
        h
=n/H;
        n
%=H;
        m
=n/M;
        n
%=M;
        
if(d>=2)
            cout
<<d<<" days"<<endl;
        
else
            
if(h+d*24>1)
                
if(m==1)
                    cout
<<h+d*24<<" hours 1 minute"<<endl;
                
else
                    cout
<<h+d*24<<" hours "<<m<<" minutes"<<endl;
            
else
                
if(h==1)
                    
if(m==1)
                        cout
<<"1 hour 1 minute"<<endl;
                    
else
                        cout
<<"1 hour "<<m<<" minutes"<<endl;
                
else
                    
if(m<5)
                    
{
                        
if(m==1)
                            cout
<<"1 minute ";
                        
else
                            cout
<<m<<" minutes ";
                        
if(n==1)
                            cout
<<"1 second"<<endl;
                        
else
                            cout
<<n<<" seconds"<<endl;
                    }

                    
else
                        cout
<<m<<" minutes"<<endl;
    }

    
return 0;
}

YOYO's Note:
按照规则算一下就可以了。要注意的是输出格式。
0是复数形式,1是单数形式。之前因为有个输出少了空格一直PE……

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值