Skip to main content

P8071 [COCI 2009/2010 #7] SPAVANAC

· One min read

题意简述

给定 2424 小时制下的时间 H:MH:M,输出 2424 小时制下比该时间早 4545 分钟对应的时刻。

解题思路

先直接减去 4545 分钟:

MM45M\gets M-45

M<0M<0,说明要向前退 11 小时:

HH1,MM+60H\gets H-1,M\gets M+60

H<0H<0,说明要向前退 11 天:

HH+24H\gets H+24

参考代码

#include <bits/stdc++.h>
using namespace std;

int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int h,m;
cin>>h>>m;
m-=45;
if(m<0){h-=1;m+=60;}
if(h<0)h+=24;
cout<<h<<' '<<m<<'\n';
return 0;
}