3rd Week Programming Questions
View Help
return
3rd week programming questions.
Note Chinese characters cannot appear in programs (including comments).
In accordance with the terms of academic integrity, I guarantee that this work is done independently.
Warm tips:
1. This assignment belongs to the online Judge topic and is enigmatic grading by the system immediately after submission.
2. Students can submit an unlimited number of answers before the deadline , and the system will take the highest score as the final result.
1 Find miles (10 points)
Topic content:
Topic content:
Highway mileage between major cities in China:
Your program will read into such a table, and then, based on the names of the two cities entered, give the mileage between the two cities.
Note: Miles between any two cities have been given and do not need to be calculated via a third transit.
Note: You do not need to enter the data, the data is given in the program input.
Input format:
First, you will read the names of a number of cities. Each name is just an English word, with no spaces or other symbols in the middle. When you read the name "# # #" (three #), the city name entered the end, # # #并不是一个城市的名字. If the number of city names to be read is n.
Then you will read an integer matrix of nxn. Each number in the first row represents the mileage between the first city in the list of cities and the other city in turn. The mileage between the same city in the table is 0.
Finally, you will read the names of two cities.
Output format:
Output the distance between the two cities.
Input Sample:
HagzouHugzoujigxng # # #
01108708
11080994
7089940
Hagzou Jigxng
Sample output:
708
time limit: 500ms memory limit: 32000kb
Import Java.util.arraylist;import Java.util.scanner;public class Main {public static void main (string[] args) {City City = New City (); City.setdistance ();//Set distance from city.getdistance ();//output The distance between the two cities. }}class City {public City () {city = new arraylist<string> (); String str = Sc.next ();//First, you will read the names of a number of cities. Each name is just an English word, with no spaces or other symbols in the middle. When you read the name "# # #" (three #), the city name entered the end, # # #并不是一个城市的名字. If the number of city names to be read is n. while (true) {if (Str.equals ("# # #")) {break;} if (Str.equals ("Huzhou")) {str = "Suzhou";} City.add (str); str = Sc.next ();} Distance = new Int[city.size ()][city.size ()]; public void Setdistance () {//set distance int mile = 0;for (int i = 0; i < distance.length; i++) {for (int j = 0; J < Distan Ce[i].length; J + +) {mile = Sc.nextint ();//Then you will read an integer matrix of nxn. Each number in the first row represents the mileage between the first city in the list of cities and the other city in turn. The mileage between the same city in the table is 0. DISTANCE[I][J] = Mile;}}} public void Getdistance () {//outputs the distance between these two cities. int int_start = City.indexof (Sc.next ()); int int_end = City.indexof (Sc.next ()); System.out.println (Distance[int_start][int_end]);} Private Arraylist<string> city;//City Private int distance[][];//distance Scanner sc = new Scanner (system.in);}
China MOOC_ object-oriented Programming--java language _ 3rd Week object Container _1 find Miles