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
KEY:这题不难,注意输出,当是1的时候没有单位s,0居然有啊……-_-我这几年的英语白读了;
Source:#include<iostream>
using namespace std;
struct node
...{
int day;
int hour;
int minute;
int second;
};
node a;
void time(int t)
...{
a.day=t/86400;
t=t%86400;
a.hour=t/3600;
t=t%3600;
a.minute=t/60;
t=t%60;
a.second=t;
if(a.day==1)
...{
a.hour+=24;
a.day=0;
}
}
void output(int t)
...{
if(t>=172800) cout<<a.day<<" days"<<endl;
if(t>=3600&&t<172800)
...{
if(a.hour>=0) cout<<a.hour<<" hour";
if(a.hour!=1) cout<<"s";
cout<<" ";
if(a.minute>=0) cout<<a.minute<<" minute";
if(a.minute!=1) cout<<"s";
cout<<endl;
}
if(t>=300&&t<=3599) cout<<a.minute<<" minutes"<<endl;
if(t<300)
...{
if(a.minute>=0) cout<<a.minute<<" minute";
if(a.minute!=1) cout<<"s";
cout<<" ";
if(a.second>=0) cout<<a.second<<" second";
if(a.second!=1) cout<<"s";
cout<<endl;
}
}
int main()
...{
// freopen("fjnu_1269.in","r",stdin);
int t;
while(cin>>t)
...{
time(t);
output(t);
}
return 0;
}