有没有大佬分享一下今天便利蜂第一题的输入的?

如题,我自己的输入在线上死活过不去~Java语言的

#算法工程师##安卓工程师#
全部评论
也是跪在输入输出了,哎!
点赞 回复 分享
发布于 2018-09-28 11:36
package bianlifeng; import java.util.LinkedHashMap; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = Integer.parseInt(sc.nextLine()); LRUCache lruCache4 = new LRUCache(n); String str; while ((str = sc.nextLine()).contains(" ")){ String[] split = str.split(" "); int key = Integer.parseInt(split[0]); int value = Integer.parseInt(split[1]); lruCache4.put(key, value); } int key = Integer.parseInt(str); System.out.println(lruCache4.get(key)); } } class LRUCache { public int capacity; public LinkedHashMap<Integer, Integer> map; public LRUCache(int capacity) { this.capacity = capacity; map = new LinkedHashMap<>(); } public int get(int key) { if (map.containsKey(key)) { int value = map.get(key); map.remove(key); map.put(key, value); return value; } else { return -1; } } public void put(int key, int value) { if (map.containsKey(key)) { map.remove(key); } if (map.size() >= capacity) { map.remove(map.keySet().iterator().next()); } map.put(key, value); } }
点赞 回复 分享
发布于 2018-09-28 11:36
我第三题的python也是跪在输入输出上了, 有没有大佬通过的呀
点赞 回复 分享
发布于 2018-09-28 11:48

相关推荐

xxxxOxo:这公司幽默得很,要了简历半天一点动静都没有,过一会就给你发个邮件让你做测试,做完又没后文了,纯溜人
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务