跳到正文

题解

题解:P15521 [CCC 2016 J4] Arrival Time

xs1014约 1 分钟
原文
文章信息与版本

文章信息

收录
2026年3月12日
更新
2026年3月12日
篇幅
约 1 分钟
题目
P15521

版本

  1. v2当前
  2. v1

#题目思路

本题重点在于如何判断此时是否在高峰期内。 可以考虑将小时转化成分钟,每十分钟判断一次,如果处于高峰期,计时便增加二十分钟,否则增加十分钟,这样就可以记录所用时间且保持时间正常流逝。

C++
#include <bits/stdc++.h>
using namespace std;
string s;
int h,m,t=120;
int main() {
    cin>>s;
    h=(s[1]-'0')+10*(s[0]-'0');
    m=(s[4]-'0')+10*(s[3]-'0');
    int time=h*60+m;
    while (t!=0) {
        if(time>=420&&time<600||time>=900&&time<1140){
            time+=20;
        }else{
            time+=10;
        }
        t-=10;
    }
    h=time/60;
    if(h>=24){
        h%=24;
    }
    m=time%60;

    if(h<10){
        cout<<0<<h<<':';
        if(m<10) cout<<0;
        cout<<m;
    }else{
        cout<<h<<':';
        if(m<10) cout<<0;
        cout<<m;
    }
    return 0;
}
原文