ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

问题 M: Contest Timing

2021-07-30 17:35:25  阅读:222  来源: 互联网

标签:11 Contest int contest 问题 she time Timing Bessie


题目描述
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.
输入

  • Line 1: This line contains 3 space-separated integers, D H M, specifying the date and time at which Bessie ends the contest.D will be an integer in the range 11..14 telling the day of the month; H and M are hours and minutes on a 24-hour clock (so they range from H=0,M=0 at midnight up through H=23,M=59 at 11:59 PM).

输出

  • Line 1: The total number of minutes spent by Bessie in the contest, or -1 if her ending time is earlier than her starting time.

样例输入 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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有