Contest Timing

关于奶牛Bessie参加USACO比赛的故事,涉及时间管理与C++编程技巧,通过日期时间转换求解她在比赛中的总耗时
摘要由CSDN通过智能技术生成
题目描述

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. PROBLEM NAME: ctiming INPUT FORMAT: * 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). SAMPLE INPUT (file ctiming.in): 12 13 14 INPUT DETAILS: Bessie ends the contest on November 12, at 13:14 (that is, at 1:14 PM). OUTPUT FORMAT: * 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. SAMPLE OUTPUT (file ctiming.out): 1563 OUTPUT DETAILS:

Bessie ends the contest 1563 minutes after she starts.

翻译:

奶牛贝茜对牛奶生产行业感到厌倦,想要转而从事令人兴奋的计算机新职业。为了提高她的编码能力技能,她决定参加在线USACO比赛。因为她指出,比赛于 2011 年 11 月 11 日(11 年 11 月 11 日)开始,她为了好玩,决定下载问题并在 11:11 开始编码11 年 11 月 11 日上午 11 日。 不幸的是,贝茜的时间管理能力很差,所以她想编写一个快速程序来帮助她确保她不会花费更长的时间比赛时限超过3小时(180分钟)。给定日期,当她停止工作时,请帮助贝茜计算总数她将在比赛中花费的时间。 问题名称:比赛时间 输入格式: * 第 1 行:此行包含 3 个空格分隔的整数,D H M, 指定 Bessie 结束比赛的日期和时间。 D 将是 11..14 范围内的整数,表示 月份;H 和 M 是 24 小时制上的小时和分钟 (所以它们的范围从午夜的 H=0,M=0 到 H=23,M=59 在晚上 11:59)。 示例输入(文件 ctiming.in): 12 13 14 输入详细信息: Bessie 于 11 月 12 日 13:14(即下午 1:14)结束比赛。 输出格式: * 第 1 行:Bessie 在比赛中花费的总分钟数,或 -1 如果她的结束时间早于她的开始时间。 示例输出(文件 ctiming.out): 1563 输出详细信息: 贝茜在比赛开始后 1563 分钟结束比赛。

样例输入 复制
12 13 14
样例输出 复制
1563
提示

Solution Notes:

   A key to making the problem easy to solve is to write a function that converts from (day, hour, minute) to a single integer that reflects an absolute count of number of minutes since some pre-determined starting point. In the sample C solution below, the function total_mins() computes the total number of minutes elapsed since the beginning of the month. Using this function, it is now easy to compute the number of minutes in the difference of two dates - we first convert the two dates into integers, and then simply subtract!

解决方案说明:

  使问题易于解决的关键是编写一个函数,将(日、小时、分钟)转换为单个整数,该整数反映自某个预先确定的起点以来的绝对分钟数。在下面的示例 C 解决方案中,函数total_mins() 计算自月初以来经过的总分钟数。使用此函数,现在可以轻松计算两个日期之差的分钟数 - 我们首先将两个日期转换为整数,然后简单地相减!

代码

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    int d,h,m;
    cin>>d>>h>>m;
    if(d<11||d==11&&h<11||d==11&&h==11&&m<11)
    {
        cout<<-1;
    }
    else 
    {
        cout<<((d-11)*24+h-11)*60+m-11;
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值