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 a18945028152 at 2019-03-07 20:02:59 on Problem 2503
import java.util.Scanner;
import java.util.Hashtable;

public class poj2503{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        Hashtable< String,String> table = new Hashtable< String, String>();
        String input;
        String [] array=new String[2];
        while(sc.hasNext()){
            input=sc.nextLine();
            if(input.length()==0) {break;}
            array=input.split(" ");
            table.put(array[1],array[0]);//put() 的作用是对外提供接口,让Hashtable对象可以通过put()将“key-value”添加到Hashtable中。
        }
        while(sc.hasNext()){
           input=sc.nextLine();
         if(table.get(input)!=null) { 
        	 System.out.println(table.get(input));}//get() 的作用就是获取key对应的value,没有的话返回null
         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