import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Test {     public static void main(String[] args){         Scanner in = new Scanner(System.in);         int count = in.nextInt();         HashMap<String,Integer> a=new HashMap<String, Integer>(count);         LinkedList<String> q=new LinkedList<String>();         in.nextLine();         ArrayList<String> h=new ArrayList<String>();         while(in.hasNext()) {          String str=in.nextLine();          if(str.equals("end")) {          break;          }          h.add(str);         }         for(String k:h) {            String[] strs=k.split(" ");          String x=strs[0];int y=Integer.valueOf(strs[1]);          if(a.containsKey(x)) {          int c=a.get(x);              if(c<y) {              a.put(x, y);              q.remove(x);              q.add(x);              }          }else if(a.size()<count) {          a.put(x, y);          q.push(x);          }else {          String out=q.pop();          int outt=a.get(out);          System.out.println(out+" "+outt);          a.put(x, y);          q.push(x);          }         }     } } 求帮忙看下 这个对不对啊? 还有就是 我始终没搞清楚如何算是输入结束呢?这里我自己测试的时候加end才行 他题里面的那个要怎么写才能表示输入结束?
点赞 1

相关推荐

码农索隆:想看offer细节
点赞 评论 收藏
分享
凉风落木楚山秋:哈工爷200也去吗
点赞 评论 收藏
分享
07-25 10:17
仰恩大学 营销
bg双非,被挂了
投递拼多多集团-PDD等公司10个岗位
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务