才发现我没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);         }     } }
点赞 评论

相关推荐

昨天 11:27
门头沟学院 Java
点赞 评论 收藏
分享
07-29 14:37
门头沟学院 Java
点赞 评论 收藏
分享

牛客热帖

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务