• 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开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦

  • 相关阅读:
    idea中删除断点与删除所有断点
    ​力扣解法汇总1624-两个相同字符之间的最长子字符串
    form表单input标签回车键禁用表单提交,走js方法提交
    DDD - 理论到落地从统一语言开始
    ARouter - 组件化通信方案
    全局路线规划导读
    记踩HttpRequest设置header无效导致404问题
    k8s笔记资源限制,亲和和性 污点和容忍
    数据集 | 目录一览表
    AWS 疑难问题——ECS传递环境变量给C#应用程序
  • 原文地址:https://blog.csdn.net/m0_67403240/article/details/126112763