#include<iostream>#include<string>#include<cstdint>#include<cmath>usingnamespacestd;usingu32=uint32_t;intmain(){u32t;cin>>t;for(u32i=0;i<t;++i){cout<<"case #"<<i<<":\n";u32n,h=0,m=0;cin>>n;doubles=0;for(u32j=0;j<n;++j){stringtime;cin>>time;u32hh,mm;doubless;sscanf(time.data(),"%u:%u:%lf",&hh,&mm,&ss);h+=hh;// n is small enough, and u32 & double can hold all datam+=mm;// sumed up, to postpone carries. So we do not carrys+=ss;// eagerly. ^_^}/* Process carrying */{m+=s/60;s=remainder(s,60);auto[quot,rem]=div(m,60);h+=quot;m=rem;h%=24;}if(h>=4&&h<12){cout<<"Good morning!\n";}elseif(h>=12&&h<18){cout<<"Good afternoon!\n";}elseif(h>=18&&h<22){cout<<"Good evening!\n";}else{cout<<"Good night!\n";}}}
直接用60进制转换的话会比较烦。。需要fmod函数
include
include
int main()
{
int hour,minute,n,i,k,m,j;
double second,N,s;
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
scanf(“%d”,&k);
N=0,s=0,m=0;
printf(“case #%d:\n”,i-1);
for(j=1;j<=k;j++)
{
scanf(“%d:%d:%lf”,&hour,&minute,&second);
}
全部转为秒数,用double来算
include
using namespace std;
int T;
double now;
double cal_time(const string& tmp)
{
double hour,minute,seconds;
sscanf(tmp.c_str(),”%lf:%lf:%lf”,&hour,&minute,&seconds);
return hour3600+minute60+seconds;
}
void solve()
{
int n;
cin>>n;
now=0;
for(int i=1;i<=n;i++)
{
string tmp;
cin>>tmp;
now+=cal_time(tmp);
}
while(now>=86400) now-=86400;
if(now-14000>=0 && now-43200<0) cout<<”Good morning!”<=0 && now-64800<0) cout<<”Good afternoon!”<=0 && now-79200<0) cout<<”Good evening!”<<endl;
else cout<<”Good night!”<<endl;
return;
}
int main()
{
scanf(“%d”,&T);
for(int step=0;step<T;step++)
{
printf(“case #%d:\n”,step);
solve();
}
return 0;
}