pat甲级 1006 Sign In and Sign Out

题目:At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in's and out's, you are supposed to find the ones who have unlocked and locked the door on that day.

第一行输入的是今天总共有几条出入记录,记为M。
下面的M行是记录,员工号记为ID_number;进入时间记为Sign_in_time,出去时间记为Sign_out_time,进出时间均为HH:MM:SS格式。
要求 我们输出最早进入和最晚出去的员工ID(输出的两个ID之间有空格别忘了。)


输入格式:

3
CS301111 15:30:28 17:00:10
SC3021234 08:00:00 11:25:25
CS301133 21:45:00 21:58:40

输出格式:

SC3021234 CS301133

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class Main {

    public static void main(String[] args) throws ParseException {
        String morning = "24:00:00";//morning代表最早出去的时间
        String evening = "00:00:00";//evening代表最晚出去的时间
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();//获取有几个人上班
        if(n==0){//没人来过,就没有lock和unlock
            return;
        }
        String [][]member = new String[n][3];
        scanner.nextLine();//以enter作为结束符
        for(int i=0;i<n;i++){
            member[i] = scanner.nextLine().split(" ");
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");//设定格式

        Date minDate1 = dateFormat.parse(member[0][1]);
        Date maxDate1 = dateFormat.parse(member[0][2]);
        int min=0;
        int max = 0;
        for(int i=1;i<n;i++){
            Date date1 = dateFormat.parse(member[i][1]);
            if(minDate1.after(date1)){//after函数
                min = i;
            }
        }
        for(int i=1;i<n;i++){
            Date date1 = dateFormat.parse(member[i][2]);
            if(maxDate1.before(date1)){//before函数
                max = i;
            }
        }
        System.out.print(member[min][0]+" "+member[max][0]);


    }
}

有个测试点1过不了  如果有大佬知道的话,可以说一下,感谢!!!

 

posted @ 2021-04-05 15:55  chenyuan#  阅读(57)  评论(0编辑  收藏  举报