Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
谁能帮忙看看,一直WA!!!import java.io.*; import java.util.*; public class Main { public static void main(String args[]) throws Exception { BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); String string = new String(); StringTokenizer st; LinkedList dictionary[] = new LinkedList[29997]; while (true) { String english, foreign; string = stdin.readLine(); if (string.length() == 0) { break; } st = new StringTokenizer(string); english = st.nextToken(); foreign = st.nextToken(); int location = hash(foreign); //get hashed location dictionary[location] = new LinkedList(); dictionary[location].add(dictionary[location].size(), new item(english, foreign)); } while ( (string = stdin.readLine()) != null) { st = new StringTokenizer(string); String temstring=st.nextToken(); int location = hash(temstring); //get hashed location int i = 0; if (dictionary[location] == null) { System.out.println("eh"); } else { item tem = new item(); for (i = 0; i < dictionary[location].size(); i++) { tem = (item) (dictionary[location].get(i)); if ( (tem.foreign).equals(temstring)) { break; } } if (i < dictionary[location].size()) { System.out.println(tem.english); } else { System.out.println("eh"); } } } } static int hash(String string) { int h = 1; for (int i = 0; i < string.length(); i++) { h = h + string.charAt(i)*3; } return h % 3000; } private static class item { String english, foreign; public item() {} public item(String english, String foreign) { this.english = english; this.foreign = foreign; } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator