我没sort,竟然过了80.。。有人把这个题得牛客网连接找出来了,我测了一下,sort以后就过了 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);         }     } }
点赞 5

相关推荐

熊大不大:总之很难,我偷偷听到字节项目的人说,现在的人越来越人,学历越来越高,就是往难的面试,择优而选
发面经攒人品
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务