zoukankan      html  css  js  c++  java
  • 公交查询系统----待完成--------一次换乘

      1 using System;
      2 using System.Collections.Generic;
      3 using System.Linq;
      4 using System.Text;
      5 
      6 namespace Bus
      7 {
      8     class Program
      9     {
     10         //站点2------->站点112
     11         static void Main(string[] args)
     12         {
     13             List<Car> carlist = new List<Car>();
     14             carlist.Add(  new Car
     15             {
     16                 Id = "班车5",
     17                 Stations = new Station[]{
     18                     new Station{Name="站点1",NearStation=new Station[]{}},
     19                     new Station{Name="站点2"},
     20                     new Station{Name="站点3"},
     21                     new Station{Name="站点4"},
     22                     new Station{Name="站点5"},
     23                     new Station{Name="站点6"},
     24                     new Station{Name="站点7"},
     25                     new Station{Name="站点8"},
     26                     new Station{Name="站点9"},
     27                     new Station{Name="站点10"},
     28                     new Station{Name="站点11"},
     29                     new Station{Name="站点12"},
     30                 }
     31 
     32             });
     33 
     34             carlist.Add( new Car
     35             {
     36                 Id = "班车2",
     37                 Stations = new Station[]{
     38                     new Station{Name="站点13"},
     39                     new Station{Name="站点12"},
     40                     new Station{Name="站点7"},
     41                     new Station{Name="站点14"},
     42                     new Station{Name="站点15"},
     43                     new Station{Name="站点16"},
     44                     new Station{Name="站点17"},
     45                     new Station{Name="站点18"},
     46                     new Station{Name="站点19"},
     47                     new Station{Name="站点110"},
     48                     new Station{Name="站点111"},
     49                     new Station{Name="站点112"},
     50                 }
     51 
     52             });  Station s = new Station();
     53           
     54  s.Name = "站点5";
     55             Station e = new Station();
     56 
     57             e.Name = "站点7";
     58           
     59             Solution sln = new Solution(carlist,s,e);
     60             sln.Find();
     61             Console.Read();
     62         }
     63 
     64     }
     65 
     66     //班车
     67     public class Car
     68     {
     69         private string id;
     70 
     71         public string Id
     72         {
     73             get { return id; }
     74             set { id = value; }
     75         }
     76 
     77         private Station[] stations;
     78 
     79         internal Station[] Stations
     80         {
     81             get { return stations; }
     82             set { stations = value; }
     83         }
     84 
     85 
     86     }
     87     //站点
     88     public class Station
     89     {
     90 
     91         string name;
     92         Station[] nearStation;
     93 
     94         internal Station[] NearStation
     95         {
     96             get { return nearStation; }
     97             set { nearStation = value; }
     98         }
     99         public string Name
    100         {
    101             get { return name; }
    102             set { name = value; }
    103         }
    104     }
    105     //换车站点
    106     public class StationTurn : Station
    107     {
    108         string attachtment;
    109 
    110         public string Attachtment
    111         {
    112             get { return attachtment; }
    113             set { attachtment = value; }
    114         }
    115 
    116     }
    117 
    118     public class Solution
    119     {
    120         List<Car> listcar;//所有班车数据
    121         List<Car> startcarlist;//起点站牌
    122         List<Car> endcarlist;//终点站牌
    123         Station start;
    124         Station end;
    125 
    126         public Solution(List<Car> listcar, Station start, Station end)
    127         {     this.start = start;
    128             this.end = end;
    129             this.listcar = listcar;
    130             this.startcarlist = FindCar(start.Name);
    131             this.endcarlist = FindCar(end.Name);
    132        
    133         }
    134         public void Find()
    135         {
    136          //   List<Car> hasCarsStartInEnd = endcarlist.Where(m => m.Id == start.Name).ToList();//在终点站牌上有起点站牌的班车
    137   
    138 
    139             foreach (Car c in startcarlist)
    140             {
    141                 foreach (Station s in c.Stations)
    142                 {
    143                     foreach (Car n in  FindCar(s.Name))
    144                     {
    145                     if (n.Stations.Select(m => m.Name).Contains(end.Name))
    146                         {
    147                             Console.WriteLine("" + c.Id + "" + s.Name + "站下车换乘" + FindCar(s.Name).Where(m => {
    148                                 for (int i = 0; i < m.Stations.Length; i++)
    149                                 {
    150                                     if (m.Stations[i].Name == end.Name)
    151                                         return true;
    152                                 }
    153                                 return false;
    154                             }).First().Id);
    155 
    156                         }
    157                     }
    158               
    159                 }
    160             }
    161 
    162         }
    163 
    164         //找指点站的站牌
    165         private List<Car> FindCar(string StationName)
    166         {
    167             List<Car> list = new List<Car>();
    168             foreach (Car c in listcar)
    169             {
    170                 if (c.Stations.Select(m=>m.Name).Contains(StationName))
    171                 {
    172                     list.Add(c);
    173                 }
    174             }
    175             return list;
    176         }
    177     }
    178 }

    最近特无聊,且经常用公交查询系统,突然想自己也做出一个来,希望能坚持下去。

    功能描述:能实现公交与地铁,公交与公交,地铁与地铁的(0,1,2,3,4换乘方式),班车,站点的数据由管理员后台管理,与维护。要面向编程。要考虑到以后webservice服务。

  • 相关阅读:
    hdu 2296 AC自动机+DP+路径字符串记录(较麻烦)
    HDU
    hdu 2243(poj2778的加强版!(AC自动机+矩阵))
    Poj3691(AC自动机+DP(简单题))
    后台样式升级1.
    那些可以在数据库里做的事:分页与过滤
    常用的几个单页应用程序网站分享
    Javascript生成二维码(QR)
    户端页面中读取串口操作
    GridView事件分析
  • 原文地址:https://www.cnblogs.com/lifeOfIT/p/3358778.html
Copyright © 2011-2022 走看看