java 代码在eclipse上能运行,在oj系统就有错误,代码的bug在哪里,怎么修改?
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int N = sc.nextInt();
MultiValueMap<String, String> stringMultiValueMap = new LinkedMultiValueMap<>();
while (N-- > 0) {
String id = sc.next();
String time = sc.next();
stringMultiValueMap.add(id, time);
}
Set<String> keySet = stringMultiValueMap.keySet();
for (String key : keySet) {
List<String> values = stringMultiValueMap.getValues(key);
if (values.size() < 6)
continue;
ArrayList<Integer> total_times = new ArrayList<>();
for (String value : values) {
int h = Integer.parseInt(value.substring(0, 2));
int d = Integer.parseInt(value.substring(3, 5));
int s = Integer.parseInt(value.substring(6, 8));
int total_time = h * 3600 + d * 60 + s;
total_times.add(total_time);
}
Collections.sort(total_times);
if (check(total_times))
System.out.println(key);
}
}
}
private static boolean check(ArrayList<Integer> list) {
for (int i = 0; i <= list.size() - 6; i++) {
for (int j = i + 1; j < i + 6; j++) {
if (Math.abs(list.get(i) - list.get(j)) >= 3600)
return false;
}
}
return true;
}
}
interface MultiValueMap<K, V> {
void add(K key, V value);
void add(K key, List<V> values);
void set(K key, V value);
void set(K key, List<V> values);
void set(Map<K, List<V>> values);
List<V> remove(K key);
void clear();
Set<K> keySet();
List<V> values();
V getValue(K key, int index);
List<V> getValues(K key);
int size();
boolean isEmpty();
boolean containsKey(K key);
}
class LinkedMultiValueMap<K, V> implements MultiValueMap<K, V> {
protected Map<K, List<V>> mSource = new LinkedHashMap<K, List<V>>();
public LinkedMultiValueMap() {
}
@Override
public void add(K key, V value) {
if (key != null) {
if (!mSource.containsKey(key))
mSource.put(key, new ArrayList<V>(2));
mSource.get(key).add(value);
}
}
@Override
public void add(K key, List<V> values) {
for (V value : values) {
add(key, value);
}
}
@Override
public void set(K key, V value) {
mSource.remove(key);
add(key, value);
}
@Override
public void set(K key, List<V> values) {
mSource.remove(key);
add(key, values);
}
@Override
public void set(Map<K, List<V>> map) {
mSource.clear();
mSource.putAll(map);
}
@Override
public List<V> remove(K key) {
return mSource.remove(key);
}
@Override
public void clear() {
mSource.clear();
}
@Override
public Set<K> keySet() {
return mSource.keySet();
}
@Override
public List<V> values() {
List<V> allValues = new ArrayList<V>();
Set<K> keySet = mSource.keySet();
for (K key : keySet) {
allValues.addAll(mSource.get(key));
}
return allValues;
}
@Override
public List<V> getValues(K key) {
return mSource.get(key);
}
@Override
public V getValue(K key, int index) {
List<V> values = mSource.get(key);
if (values != null && index < values.size())
return values.get(index);
return null;
}
@Override
public int size() {
return mSource.size();
}
@Override
public boolean isEmpty() {
return mSource.isEmpty();
}
@Override
public boolean containsKey(K key) {
return mSource.containsKey(key);
}
}