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

太美妙了。。。用Java做连异常处理都用上了。。。呵呵

Posted by sgxiao at 2008-09-07 16:45:59 on Problem 2503
/*
Author: sgxiao
Title: 2503 -- Babelfish
LANG: java
Date : Sun Sep  7 15:23:00 CST 2008
*/
import java.util.*;
import java.math.*;
import java.util.regex.*;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		Map<String, String> dictionary = new HashMap<String, String>();
		
		String eng;
		String niaoyu;
		String search;
		
		while(scanner.hasNextLine() ) {
			String nextline = scanner.nextLine();
			eng = nextline.split(" ")[0];
			try {
				niaoyu = nextline.split(" ")[1];
			} catch (java.lang.ArrayIndexOutOfBoundsException e) {
				search = eng;
				break;
			}
			dictionary.put(niaoyu, eng);
		}
		
		while(scanner.hasNext()) {
			search = scanner.next();
			String result;
			if( (result = dictionary.get(search)) != null) {
				System.out.println(result);
			} else {
				System.out.println("eh");
			}
		}
	}
}


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