http://mooc.study.163.com/learn/ZJU-1000004001?tid=1000005000#/learn/ojhw?id=1000215000
1 package J3; 2 import java.util.*; 3 public class Test2 { 4 private HashMap<String, Integer> city = new HashMap<String, Integer>(); 5 private int cityAmount = 0; 6 7 public void init(){ 8 Scanner in = new Scanner(System.in); 9 String next = new String(); 10 while( !(next = in.next()).equals("###")){ 11 12 city.put(next, cityAmount); 13 cityAmount++; 14 } 15 // System.out.println(cityAmount); 16 int[][] table = new int[cityAmount][cityAmount]; 17 for( int i = 0; i < cityAmount; i++ ){ 18 for( int j = 0; j < cityAmount; j++){ 19 table[i][j] = in.nextInt(); 20 } 21 } 22 String compareA = new String(); 23 String compareB = new String(); 24 compareA = in.next(); 25 compareB = in.next(); 26 in.close(); 27 System.out.println(table[city.get(compareA)][city.get(compareB)]); 28 } 29 30 public static void main(String[] args){ 31 new Test2().init(); 32 } 33 }
哎,没有思路时,首先想到的还是过程化解决问题,,,还是读书少啊。。