50,528
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = null;
str= sc.nextLine();
int n =Integer.parseInt(str);
String[] ss = null;
Map<String, String> mapTime = new HashMap<String, String>();
Map<String, Integer> mapCount = new HashMap<String, Integer>();
Set<String> result = new HashSet<String>();
String time = null;
for (int i = 0; i < n; i++) {
str = sc.nextLine();
ss = str.split(" ");
if (null == mapTime.get(ss[0])) {
mapTime.put(ss[0], ss[1]);
mapCount.put(ss[0],1);
} else {
time = mapTime.get(ss[0]);
if(isSameHour(time,ss[1])) {
//如果是同一個小時內的,mapcount+1
mapCount.put(ss[0],mapCount.get(ss[0])+1);
if(mapCount.get(ss[0])==6) {
result.add(ss[0]);
}
}else {
//重置
mapTime.put(ss[0], ss[1]);
mapCount.put(ss[0],1);
}
}
}
System.out.println(result.toString());
}
public static boolean isSameHour(String aTime,String bTime) {
String[] ssATime = aTime.split(":");
String[] ssBTime = bTime.split(":");
int atimeint = Integer.parseInt(ssATime[0])*60*60+Integer.parseInt(ssATime[1])*60+Integer.parseInt(ssATime[1]);
int btimeint = Integer.parseInt(ssBTime[0])*60*60+Integer.parseInt(ssBTime[1])*60+Integer.parseInt(ssBTime[1]);
if(btimeint - atimeint > 3600) {
return false;
}else {
return true;
}
}