java代码有bug,在eclipse上可以运行,在oj系统上就有错误,但是只能运行一部分

![图片说明](https://img-ask.csdn.net/upload/201811/07/1541569581_852187.jpg)<br>
图片说明

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 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 {
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 implements MultiValueMap {
protected Map> mSource = new LinkedHashMap>();

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);
}

}

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!