本帖最后由 caruko 于 2011-6-5 21:17 编辑
计算线路做出来了,有空补上计算站点数的。 文本是 第5行 的 dt.txt- @ECHO OFF&SETLOCAL ENABLEDELAYEDEXPANSION
- set /p input=请输入起点站-终点站:
- for /f "tokens=1,2 delims=-, " %%a in ("!input!") do set "start=%%a"&set "end=%%b"
- ::取得交点。
- for /f "tokens=1,2* delims=/ " %%a in (dt.txt) do (
- set "xl_%%a=%%c"
- for %%i in (%%c) do set /a #%%i+=1
- )
- for /f "tokens=1,2 delims=#=" %%a in ('set #') do (
- if !#%%a! geq 2 set "dd_list=!dd_list! %%a"
- set "#%%a="
- )
- ::取得每个交点可到达的线路。
- for /f "tokens=2,3 delims=_=" %%a in ('set xl_') do (
- set "str=%%b"
- for /f "tokens=1,2" %%x in ("!start! !end!") do (
- if not "!str:%%x=!"=="!str!" set "start_xl=!start_xl! %%a"
- if not "!str:%%y=!"=="!str!" set "end_xl=!end_xl! %%a"
- )
- for %%D in (!dd_list!) do (
- if not "!str:%%D=!"=="!str!" (
- set "%%x=!%%x:%%D=@%%D!"
- set "@%%D=!@%%D! %%a "
- )))
- ::检查是否可直达
- for %%a in (!start_xl!) do for %%b in (!end_xl!) do if %%a==%%b set "路线=^"!start! !end!^""
- if not "!路线!"=="" goto :metic
- ::计算换乘路线
- set "查询表=^"!start!=!start_xl!^""
- set "剩余交点表=!dd_list!"
- :loop
- for %%i in (!查询表!) do (
- for /f "tokens=1* delims==" %%A in ("%%~i") do (
- for %%a in (%%B) do (
- for %%b in (!剩余交点表!) do (
- for %%c in (!@%%b!) do (
- if %%a==%%c (
- set "转车点=!转车点! %%b"
- set "剩余查询表=!剩余查询表! ^"%%A %%b=!@%%b:%%c=!^""
- for %%d in (!end_xl!) do for %%e in (!@%%b!) do if %%e==%%d (
- set "路线=!路线! ^"%%A %%b !end!^" "
- )))))))
- for %%a in (!剩余交点表!) do for %%b in (!转车点!) do set "剩余交点表=!剩余交点表:%%b=!"
- set "查询表=!剩余查询表!"
- set "剩余查询表="
- if !路线!.==. goto :loop
- ::计算站点
- :metic
- echo,路线:!路线!
- goto :eof
复制代码
|