用Map根据key查找value
Memory:19828K
Time:1547MS
import java.util.Map; import java.util.HashMap; import java.io.BufferedReader; import java.io.InputStreamReader; public class Main{ public static void main(String[] args) throws Exception{ BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); Map<String,String> map = new HashMap<String,String>(); String line = null; String words[]; while(true){ line = bf.readLine(); if(line.equals("")) break; words = line.split(" "); map.put(words[1],words[0]); } while(bf.ready()){ line = bf.readLine(); String result = map.get(line); if(result==null) System.out.println("eh"); else System.out.println(result); } } }
时间: 2025-01-05 20:44:45