Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

谁能帮忙看看,一直WA!!!

Posted by sza at 2006-03-20 11:12:24 on Problem 2503
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator