概述
输入N个员工,每个员工输出ID号,上班时间,下班时间,第一行输出 最早去的员工的ID和上班时间第二行输出 最迟走的员工的ID和下班时间第三行输出 工作最久的员工的ID和上班时间(数据瞎编的)sample input:ID100001, 07:00:00 17:00:00ID100002, 08:00:00 18:00:00ID100003, 09:00:00 21:00:00sample out:OPEN:ID100001, 07:00:00CLOSE:ID100003, 21:00:00
STAR:ID100003, 12:00:00import java.util.*;
public class Exam2017Num2 {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
String id;
String comeTime;
String goTime;
int early=0,late=0,max=0;
List employs=new ArrayList<>();
for(int i=0;i
id=sc.next();
comeTime=sc.next();
goTime=sc.next();
Employ employ=new Employ(id,comeTime,goTime);
employs.add(employ);
id=sc.nextLine();
}
for(int i=1;i
if(employs.get(i).getComeTime()
if(employs.get(i).getGoTime()>employs.get(i-1).getComeTime())late=i;
if(employs.get(i).getWorkTime()>employs.get(i-1).getWorkTime())max=i;
}
System.out.println("Early:"+employs.get(early).getId()+" "+employs.get(early).getComeTimeStr());
System.out.println("Late:"+employs.get(late).getId()+" "+employs.get(late).getGoTimeStr());
System.out.println("Max:"+employs.get(max).getId()+" "+employs.get(max).getWorkTimeStr());
}
private static class Employ{
private String id;
private String comeTime;
private String goTime;
Employ(String id,String comeTime,String goTime){
this.id=id;
this.comeTime=comeTime;
this.goTime=goTime;
}
int timeChange(String str){
int time=0;
int sec=0;
for(int i=0;i
if(str.charAt(i)>='0'&&str.charAt(i)<='9'){
time=time*10+Integer.parseInt(String.valueOf(str.charAt(i)));
if(i%2!=0){
sec=sec*60+time;
time=0;
}
}
}
return sec;
}
int getComeTime(){
return timeChange(comeTime);
}
int getGoTime(){
return timeChange(goTime);
}
int getWorkTime(){
return timeChange(goTime)-timeChange(comeTime);
}
String getWorkTimeStr(){
String WorkTimeStr;
int WorkTime=timeChange(goTime)-timeChange(comeTime);
if (WorkTime>=3600){
WorkTimeStr=String.valueOf(WorkTime/3600);
WorkTimeStr=WorkTimeStr+":";
WorkTime=WorkTime%3600;
}
else {
WorkTimeStr="00:";
}
if (WorkTime>60){
WorkTimeStr=String.valueOf(WorkTime/60);
WorkTimeStr=WorkTimeStr+":";
WorkTime=WorkTime%60;
}
else {
WorkTimeStr=WorkTimeStr+"00:";
}
WorkTimeStr=WorkTimeStr+String.format("%02d",WorkTime);
return WorkTimeStr;
}
String getId(){
return id;
}
String getComeTimeStr(){
return comeTime;
}
String getGoTimeStr(){
return goTime;
}
}
}
最后
以上就是专一纸鹤为你收集整理的计算机复试java_2017杭电计算机研究生复试笔试编程题第二题(JAVA)的全部内容,希望文章能够帮你解决计算机复试java_2017杭电计算机研究生复试笔试编程题第二题(JAVA)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复