1. 1864: 考试时间

传送门:http://oj.ecustacm.cn/problem.php?id=1864

1.1. 题意

1.1.1. 题目描述

比赛开始时间为 2011 年 11 月 11 日 11 时 11 分。

比赛结束时间为 2011 年 11 月 分。

求比赛持续了多长分钟。

1.1.2. 输入

输入三个数字,其中保证 属于属于属于

1.1.3. 输出

输出一个数字表示答案。如果结束时间早于开始时间,输出

1.2. Tag

模拟

1.3. 难度

1.4. 思路

进行时间减法即可。可以统一转换成分钟来计算:分钟,小时分钟。

只要结束时间的分钟数大于等于起始时间即可输出差,否则输出

1.5. C++:

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

int total_mins(int d, int h, int m){
  return d * 24 * 60 + h * 60 + m;
}

int main(){
    int d, h, m;
    cin >> d >> h >> m;
    if (total_mins(d,h,m) < total_mins(11,11,11))
        cout << -1;
    else
        cout << total_mins(d,h,m) - total_mins(11,11,11);
    return 0;
}

1.6. Java :

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int d = scanner.nextInt();
        int h = scanner.nextInt();
        int m = scanner.nextInt();
        int t1 = total_mins(11, 11, 11);
        int t2 = total_mins(d, h, m);
        if(t1 <= t2)
            System.out.println(t2 - t1);
        else
            System.out.println(-1);
    }
    public static int total_mins(int d, int h, int m) {
        return d * 24 * 60 + h * 60 + m;
    }
}

1.7. Python:

def read():
    return map(int, input().split())
def total_mins(d, h, m):
    return d * 24 * 60 + h * 60 + m
d, h, m = read()
t1 = total_mins(11, 11, 11)
t2 = total_mins(d, h, m)
if t1 <= t2:
    print(t2 - t1)
else:
    print(-1)

results matching ""

    No results matching ""