264 字
1 分钟
题解:P14497 [NCPC 2025] Crochet Competition

P14497 [NCPC 2025] Crochet Competition 题解#

题目传送门

思路#

模拟。

可以将每个星期映射到一个数字,方便处理。

然后再将开始和结束时间都转为从周一 00:00 起经过的总分钟数。

如果结束时间小于等于开始时间,说明已经过了一周,要将最终计算的时间加上一周。

最后就是输出了。先忽略值为 00 的单位,然后处理单复数。

  • 当只有 11 个部分的时候,直接输出;
  • 当有 22 个部分的时候,中间用 and 连接;
  • 当有 33 个部分的时候,中间用逗号分隔。

Code#

#include<bits/stdc++.h>
using namespace std;
#define int long long
string d1,d2;
int h1,h2,m1,m2;
char t;
map<string,int> mp {
{"Mon",0},
{"Tue",1},
{"Wed",2},
{"Thu",3},
{"Fri",4},
{"Sat",5},
{"Sun",6}
};
string print(int x) {
if (x==0) return "7 days";
int d=x/(24*60);
x%=(24*60);
int h=x/60,m=x%60;
vector<string> ans;
if (d>0) ans.push_back(to_string(d)+(d==1 ? " day" : " days"));
if (h>0) ans.push_back(to_string(h)+(h==1 ? " hour" : " hours"));
if (m>0) ans.push_back(to_string(m)+(m == 1 ? " minute" : " minutes"));
if (ans.size()==1) return ans[0];
if (ans.size()==2) return ans[0]+" and "+ans[1];
return ans[0]+", "+ans[1]+", "+ans[2];
}
signed main() {
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>d1>>h1>>t>>m1>>d2>>h2>>t>>m2;
int s=mp[d1]*24*60+h1*60+m1;
int e=mp[d2]*24*60+h2*60+m2;
if (e<=s) e+=7*24*60;
cout<<print(e-s);
return 0;
}
题解:P14497 [NCPC 2025] Crochet Competition
https://banglee13.github.io/posts/p14497/
作者
banglee
发布于
2025-11-14
许可协议
CC BY-NC-SA 4.0

分享文章

生成精美分享图或复制链接,与更多人分享本文。

继续阅读

沿着主题读

基于共同的标签与分类

换条路线

从其他文章中稳定抽取

最后更新于 ,距今已过 376 天

部分内容可能已过时