• MOOC_Java进阶_翁恺讲_第三周题


    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();

    }

    }

    先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦

  • 相关阅读:
    Python编程实验五:文件的读写操作
    网络编程:网络超时检测(select poll setsockopt alarm)
    黑盒测试用例设计方法案例与练习题
    rust 引用详解
    关于ASO优化的分步入门指南2
    R语言使用append函数在向量数据中的指定位置插入新的元素(一个或者多个数值)
    StatefulSet
    C语言进阶 文件操作知识(上)
    Web3时代到来:非洲兄弟已经在用它“养家糊口”
    【SSL 1588】猜道路(图论)
  • 原文地址:https://blog.csdn.net/m0_67403240/article/details/126112763