packagemooc_java进阶_d3周题;/*** 没有使用HashMap*/
importjava.util.ArrayList;importjava.util.Scanner;public classMain {public static voidmain(String[] args) {
Scanner in= newScanner(System.in);
String stopSymbol= "###";int cityNumbers = 0;boolean goOn = true;
ArrayList citys = new ArrayList();while(goOn) {
String cityOnly=in.next();if(cityOnly.equals(stopSymbol)) {break;
}else{
citys.add(cityOnly);
}
}
cityNumbers=citys.size();int n =cityNumbers;
Scanner in1= newScanner(System.in);int allN = n *n;int[] matrix = new int[allN];for (int i = 0; i < matrix.length; i++) {
matrix[i]=in1.nextInt();
}
Scanner in3= newScanner(System.in);
String[] twoCitys= new String[2];
twoCitys[0] =in3.next();
twoCitys[1] =in3.next();int count = 0;int firstCityIndex = 0;int secondCityIndex = 0;for (int j = 0; j < 2; j++) {for (int i = 0; i < n; i++) {if(citys.get(i).equals(twoCitys[j])) {
count++;if (count == 1) {
firstCityIndex=i;
}else if (count == 2) {
secondCityIndex=i;
}else{
}
}
}
}int leftCityIndex = 0;int rightCityIndex = 0;int city_D_value = 0;intli;intliInMat;if (firstCityIndex
leftCityIndex=firstCityIndex;
li=leftCityIndex;
liInMat= li * n +li;
city_D_value= secondCityIndex -firstCityIndex;
rightCityIndex= liInMat +city_D_value;
}else if (firstCityIndex >secondCityIndex) {
leftCityIndex=secondCityIndex;
li=leftCityIndex;
liInMat= li * n +li;
city_D_value= firstCityIndex -secondCityIndex;
rightCityIndex= liInMat +city_D_value;
}else{
}int distance =matrix[rightCityIndex];if (distance != 0) {
System.out.print(distance);
}else{
System.out.println("0");
}
in.close();
}
}