才发现我没sort。。。服了,题目没说闹钟有顺序,这样竟然也过了80.。。。,一下是刚才在牛客网上AC的 import java.util.Arrays; import java.util.Scanner; public class Main {     public static void main(String[] args) {         Scanner sc = new Scanner(System.in);         while ( sc.hasNextLong() ) {             int n = sc.nextInt();             int[] times = new int[n];             for (int i = 0; i < n; i++) {                 int h = sc.nextInt() * 60;                 int m = sc.nextInt();                 times[i] = h + m;             }             Arrays.sort(times);             int cost = sc.nextInt();             int sh = sc.nextInt() * 60;             int sm = sc.nextInt();             int target = sh + sm;             int left = target - cost;             int res = -1;             for (int i = 0; i < n; i++) {                 if (left == times[i]) {                     res = left;                     break;                 }             }             for (int i = 1; i < n; i++) {                 if (left > times[i - 1] && left < times[i]) {                     res = times[i - 1];                     break;                 }             }             int hour = res / 60;             int min = res % 60;             System.out.println(hour + " " + min);         }     } }
点赞 评论

相关推荐

10-17 23:18
已编辑
西北农林科技大学 Web前端
独行m:给25可以试试,但他只能给12,那就是纯纯的事精
秋招,不懂就问
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务