专栏文章
题解:P14497 [NCPC 2025] Crochet Competition
P14497题解参与者 1已保存评论 0
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @min7d8g5
- 此快照首次捕获于
- 2025/12/01 21:46 3 个月前
- 此快照最后确认于
- 2025/12/01 21:46 3 个月前
细节特别多的一道题。
对于输入,我们可以使用
getline 和 stoi 来获取信息。由于一周只有 10080 分钟,可以直接模拟。对于输出,可以搞一个输出数组来存储输出格式,处理完后再输出。注意,若天数,小时数和分钟数都相等就是 7 天。
不过我还要吐槽一下,这道题注意单复数对于萌新还是太苛刻了?
AC Code:
CPP#include<bits/stdc++.h>
using namespace std;
int d,h,m,ed,eh,em;
int f(string x){
if(x=="Mon")return 1;
else if(x=="Tue")return 2;
else if(x=="Wed")return 3;
else if(x=="Thu")return 4;
else if(x=="Fri")return 5;
else if(x=="Sat")return 6;
else return 7;
}
int main(){
string a,b;
getline(cin,a);
getline(cin,b);
string d1=a.substr(0,3);
string d2=b.substr(0,3);
h=stoi(a.substr(4,2));
m=stoi(a.substr(7,2));
eh=stoi(b.substr(4,2));
em=stoi(b.substr(7,2));
d=f(d1);
ed=f(d2);
int last=0;
if(d==ed&&h==eh&&m==em){
last=7*1440;
}else{
while(!(d==ed&&h==eh&&m==em)){
last++;
m++;
if(m==60){
m=0;
h++;
}
if(h==24){
h=0;
d++;
}
if(d==8)d=1;
}
}
int ansd=last/1440,ansh=(last%1440)/60,ansm=last%60;
vector<string>v;
if(ansd>0){
if(ansd==1)v.push_back("1 day");
else v.push_back(to_string(ansd)+" days");
}
if(ansh>0){
if(ansh==1)v.push_back("1 hour");
else v.push_back(to_string(ansh)+" hours");
}
if(ansm>0){
if(ansm==1)v.push_back("1 minute");
else v.push_back(to_string(ansm)+" minutes");
}
if(v.size()==3){
cout<<v[0]<<", "<<v[1]<<", "<<v[2];
}else if(v.size()==2){
cout<<v[0]<<" and "<<v[1];
}else{
cout<<v[0];
}
return 0;
}
相关推荐
评论
共 0 条评论,欢迎与作者交流。
正在加载评论...