其他分享
首页 > 其他分享> > 问题 M: Contest Timing

问题 M: Contest Timing

作者:互联网

题目描述
Bessie the cow is getting bored of the milk production industry, and wants to switch to an exciting new career in computing. To improve her coding skills, she decides to compete in the on-line USACO competitions. Since she notes that the contest starts on November 11, 2011 (11/11/11), she decides for fun to download the problems and begin coding at exactly 11:11 AM on 11/11/11.

Unfortunately, Bessie's time management ability is quite poor, so she wants to write a quick program to help her make sure she does not take longer than the 3 hour (180 minute) time limit for the contest. Given the date and time she stops working, please help Bessie compute the total number of minutes she will have spent on the contest.
输入

输出

样例输入 Copy
12 13 14
题目描述:给定一个输入d, h, m 天数, 小时数, 分钟数, 输出从11号11点11分到现在的时间, 如果比这个时间早输出-1
大体思路
先用分钟减去11, 如果结果小于0, 那么小时就减去1, 分钟数+= 60
再用小时减去11, 如果结果小时0, 那么天数就减去1 小时数 += 24
最后看天数是否大于等于0, 如果大于等于0那么就代表是同一天或者比这一天晚, 否则就是比这一天早, 输出-1

#include<iostream>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;
#define int long long
signed main()
{
    int d, h, m;
    cin >> d >> h >> m;
    int res = 0;
    int _m = m - 11;
    if(_m < 0){h --; _m += 60;};
    int _h = h - 11;
    if(_h < 0){d --; _h += 24;}
    int _d = d - 11;
    res = _m + _h * 60 + _d * 24 * 60;
    if(res < 0 || _d < 0)cout << -1 << endl;
    else cout << res << endl;
    return 0;
}

标签:11,Contest,int,contest,问题,she,time,Timing,Bessie
来源: https://www.cnblogs.com/jw-zhao/p/15080671.html