标题:小白求助大神,自己写的代码在eclipse可以运行,但是评测系统不给过,自己却 ...
取消只看楼主
java小白兔
Rank: 1
等 级:新手上路
帖 子:29
专家分:3
注 册:2018-11-7
结帖率:100%
 问题点数:0 回复次数:2 
小白求助大神,自己写的代码在eclipse可以运行,但是评测系统不给过,自己却不知怎么改,求大神写一个能过的.............

搜索更多相关主题的帖子: 代码 eclipse 运行 系统 
2018-11-08 08:49
java小白兔
Rank: 1
等 级:新手上路
帖 子:29
专家分:3
注 册:2018-11-7
得分:0 
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);
    }
}
2018-11-11 09:20
java小白兔
Rank: 1
等 级:新手上路
帖 子:29
专家分:3
注 册:2018-11-7
得分:0 
1.....
2018-11-18 12:42



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-491078-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.307966 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved