表结构:
YunXingQuFrom LuXian
北京 北京,徐州,蚌埠,南京,南京
重庆 重庆,重庆北,徐州,渠县,达州,宣汉,万源
。。 。 。。比如我要从 北京 到 达州 ,可以从 徐州 转车。
这个程序好像好难写???
解决方案 »
- 在.net里为什么js获取到的FileUpload的绝对路径是C:\fakepath\ 无论怎么取都是C:\fakepath\+文件名
- asp.net调用JS组件的问题
- vs2005初接触的一些疑惑
- 怎样使页面内的所有控件失效(不能填写数据,只能查看)
- 『请问』:asp.net做的web应用程序在客户端浏览不了,可能是什么原因造成的?
- “存储过程”的名字怎么修改
- **************************请问关于vs2008里html服务器控件的问题
- 这个javascript问题太奇怪了,请问大家有没有遇到过?
- 请教一个问题,关于省市联动
- 为什么我的ASP.NET页面无法正常显示?
- asp.net中Sqlserver数据库上传问题
- 谁能发一份有关OA系统用网站的详细设计给我。马上送100分.
说个大概思路:
先一个数组将所有站名存起来
arrName[n]="北京" ......
然后用另一数组存关系:一站一站地存。
比如arrName[0]="北京",arrName[1]="徐州"
那么:
arrRelation[0][1]=1 arrRelation[1][0]=1
......然后就是找路的算法了。
function FindWay(int iEnter,int iOut)
{
//先取出 arrRelation[iEnter][]=1 的
//再循环 判断里面有没有 iOut(第二维的维数)
//如果没有就继续深入找将 第二维换成第一维,再循环......
}
临时想的啊。可能不是最优。
Declare @Luxian varchar(1000)
create table #t(city varchar(30))
Select top 1 @Luxian=Luxian from a where YunXingQuFrom='北京'
Declare MyCur Cursor for
Select LuXian From a where '达州' in LuXian
Open MyCur
Fetch next from MyCur into @temp
while @@fetch_status=0
Begin
If Exists (Select 0 from dbo.GetRecords(@Luxian),@temp))
begin
Insert into #t (city) select * from dbo.GetRecords(@Luxian)
end
Fetch next from MyCur into @temp
end
close MyCur
deallocate MyCur
select * from #t
create function GetRecords(@str varchar(8000))
returns @Rec table (Record varchar(40))
as
begin
declare @s varchar(8000)
declare @r varchar(40)
declare @i int
set @s=@str
set @i=CHARINDEX(',',@s)
while @i>0
begin
set @r=left(@s,@i-1)
if not exists (select * from @Rec where record=@R)
insert @Rec values (@R)
set @s=right(@s,len(@s)-@i)
set @i=CHARINDEX(',',@s)
end
if len(@s)>0
if not exists (select * from @Rec where record=@s)
insert @Rec values (@s)return
end
while @@fetch_status=0
Begin
If Exists (Select 0 from dbo.GetRecords(@Luxian) where Record in (@temp))
begin
Insert into #t (city) select * from dbo.GetRecords(@Luxian)
end