hdu 1234 开门人和关门人

本文详细解析了如何从一系列包含签到时间、签离时间的记录中,找出每天最早和最晚进行操作的人。通过算法实现,有效解决了实际应用中的数据处理问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		while(n-->0){// 天数
			int m = sc.nextInt();
			String nameMax = "";
			String nameMin = "";
			int max = -100;
			int min = Integer.MAX_VALUE;
			sc.nextLine();//接回车符
			while(m-->0){// 条目数
				String input = sc.nextLine();
				String strs[] = input.split(" ");
				//签到时间
				int temp = countTime(strs[1]);
				if(min>temp){
					min = temp;
					nameMin = strs[0];
				}
				//签离时间
				temp = countTime(strs[2]);
				if(max<temp){
					max = temp;
					nameMax = strs[0];
				}
			}
			System.out.println(nameMin+" "+nameMax);
		}
	}

	public static int countTime(String time) {
		String[] strs = time.split(":");
		int hours = Integer.parseInt(strs[0]);
		int minute = Integer.parseInt(strs[1]);
		int second = Integer.parseInt(strs[2]);
		return hours * 3600 + minute * 60 + second;
	}

}






//超时

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long max = 0,min = 0,temp_ex=0;
		int max_output=0,min_output=0;
		//不懂java的可能看不懂这个类的用法,我也是复习一下姿势
		DateFormat df = new SimpleDateFormat("yyyyHH:mm:ss");
		int n = sc.nextInt();
		while(n-->0){
			//初始化数据
			max_output=0;
			min_output=0;
			max = -1;
			min = Long.MAX_VALUE;
			//输入语句
			int m = sc.nextInt();
			String[][] tests = new String[m][3];
			//输入数据
			for (int i = 0; i < tests.length; i++) {
				for (int j = 0; j < 3; j++) {
					tests[i][j] = sc.next();
				}
				try {
					temp_ex = df.parse(1971+tests[i][1]).getTime();
					if(temp_ex<min){
						min = temp_ex;
						min_output = i;
					}
					temp_ex = df.parse(1971+tests[i][2]).getTime();
					if(temp_ex>max){
						max = temp_ex;
						max_output = i;
					}
				} catch (ParseException e) {
					e.printStackTrace();
				}
			}
			System.out.println(tests[min_output][0]+" "+tests[max_output][0]);
		}
	}

}

开门人和关门人

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12133    Accepted Submission(s): 6136


Problem Description
每天第一个到机房的人要把门打开,最后一个离开的人要把门关好。现有一堆杂乱的机房签
到、签离记录,请根据记录找出当天开门和关门的人。
 

Input
测试输入的第一行给出记录的总天数N ( > 0 )。下面列出了N天的记录。
每天的记录在第一行给出记录的条目数M ( > 0 ),下面是M行,每行的格式为

证件号码 签到时间 签离时间

其中时间按“小时:分钟:秒钟”(各占2位)给出,证件号码是长度不超过15的字符串。
 

Output
对每一天的记录输出1行,即当天开门和关门人的证件号码,中间用1空格分隔。
注意:在裁判的标准测试输入中,所有记录保证完整,每个人的签到时间在签离时间之前,
且没有多人同时签到或者签离的情况。
 

Sample Input
  
3 1 ME3021112225321 00:00:00 23:59:59 2 EE301218 08:05:35 20:56:35 MA301134 12:35:45 21:40:42 3 CS301111 15:30:28 17:00:10 SC3021234 08:00:00 11:25:25 CS301133 21:45:00 21:58:40
 

Sample Output
  
ME3021112225321 ME3021112225321 EE301218 MA301134 SC3021234 CS301133
 

Source






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值