题解:P14497 [NCPC 2025] Crochet Competition
这个题只需要把给定的起始时间换成时间戳,相减后在转化为天时分的顺序
有一个细节是如果开始结束时间戳分别是 与 ,当 大于 时直接用 减 ,但在 时,也就是不在一周内时,把 直接加上一周的时间,而不能直接 减
代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
string x;
int s,t,hh,mm,d,h,m;
char kkk;
map<string,int>ma;
void wd(int p)
{
cout<<p<<" day";
if(p>1) cout<<"s";
}
void wh(int p)
{
cout<<p<<" hour";
if(p>1) cout<<"s";
}
void wm(int p)
{
cout<<p<<" minute";
if(p>1) cout<<"s";
}//加复数形式
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
ma["Mon"]=0;
ma["Tue"]=1;
ma["Wed"]=2;
ma["Thu"]=3;
ma["Fri"]=4;
ma["Sat"]=5;
ma["Sun"]=6;
cin>>x>>hh>>kkk>>mm;
s=ma[x]*60*24+hh*60+mm;
cin>>x>>hh>>kkk>>mm;
t=ma[x]*60*24+hh*60+mm;//转化时间戳
if(s==t)//相等输出7天
{
cout<<"7 days"<<endl;
return 0;
}
if(t<s) t+=7*60*24;//不在同一周
int d,n,m=t-s;
d=m/(60*24);
m-=d*60*24;
h=m/60;
m-=h*60;//转化
if(d&&h&&m)//分类讨论
{
wd(d);
cout<<", ";
wh(h);
cout<<", ";
wm(m);
cout<<"\n";
}
else if(h&&m)
{
wh(h);
cout<<" and ";
wm(m);
cout<<"\n";
}
else if(d&&m)
{
wd(d);
cout<<" and ";
wm(m);
cout<<"\n";
}
else if(d&&h)
{
wd(d);
cout<<" and ";
wh(h);
cout<<"\n";
}
else if(d)
{
wd(d);
cout<<"\n";
}
else if(h)
{
wh(h);
cout<<"\n";
}
else if(m)
{
wm(m);
cout<<"\n";
}
return 0;
}