zoukankan      html  css  js  c++  java
  • 第二周星期一

    1、新增代码设计

    * FileName:FileIO.java
    * 处理文件的读写
    */
    public class FileIO {

    public static String READ_PATH; //读取路径
    public static String WRITE_PATH; //写入路径

    /**
    * 读取文件初始化地铁线路
    */
    public static void readSubway(List < Station > map) throws IOException {
    File readfile = new File(READ_PATH);
    BufferedReader reader = new BufferedReader(new FileReader(readfile));
    String tempString = null;
    while ((tempString = reader.readLine()) != null) {
    int trim = tempString.indexOf(' ');
    String lineNo = tempString.substring(0, trim);
    tempString = tempString.substring(trim + 1);
    String[] stations = tempString.split(" ");

    for (String s: stations) { //初始化站点
    Station test = new Station(s, lineNo); //要添加的车站
    if (map.contains(test)) { //已经有了
    int index = (map.indexOf(test));
    map.get(index).isInterchangeStation = true;
    map.get(index).line.add(lineNo);
    } else {
    map.add(test);
    }
    }

    for (int i = 0; i < stations.length; i++) { //添加相邻站点
    Station s = new Station(stations[i], lineNo);
    int index = (map.indexOf(s));
    if(stations.length==1) {
    break;
    }
    if (i == 0) {
    Station pres = new Station(stations[i + 1], lineNo);
    int preindex = (map.indexOf(pres));
    map.get(index).linkStations.add(map.get(preindex));
    } else if (i == stations.length - 1) {
    Station nexts = new Station(stations[i - 1], lineNo);
    int nextindex = (map.indexOf(nexts));
    map.get(index).linkStations.add(map.get(nextindex));
    } else {
    Station pres = new Station(stations[i + 1], lineNo);
    int preindex = (map.indexOf(pres));
    Station nexts = new Station(stations[i - 1], lineNo);
    int nextindex = (map.indexOf(nexts));
    map.get(index).linkStations.add(map.get(preindex));
    map.get(index).linkStations.add(map.get(nextindex));
    }
    }
    }
    reader.close();
    }

    2.计划明天继续完成第一个功能,实现地图文本的读入

    3.问题,之前没有见过实现读入的程序,设计,学习,查询询问过程比较艰难,进展缓慢。

  • 相关阅读:
    HDU 5912 Fraction (模拟)
    CodeForces 722C Destroying Array (并查集)
    CodeForces 722B Verse Pattern (水题)
    CodeForces 722A Broken Clock (水题)
    CodeForces 723D Lakes in Berland (dfs搜索)
    CodeForces 723C Polycarp at the Radio (题意题+暴力)
    CodeForces 723B Text Document Analysis (水题模拟)
    CodeForces 723A The New Year: Meeting Friends (水题)
    hdu 1258
    hdu 2266 dfs+1258
  • 原文地址:https://www.cnblogs.com/pekey/p/11414761.html
Copyright © 2011-2022 走看看