3.22第一次结对作业每日总结
我的队友是高一榀。
今天用了大约一个半小时的
时间进行最少换乘的查询,
但是存在不完全遍历的问题
一直尝试解决,但还没有解
决。
public int findfewrole(String startname,String stopname) throws Exception {
int number=10,location=-1;
char roles[]=new char[1000];
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/kebiao", "root", "123456");
String sql="WITH RECURSIVE transfer(startname, stopname, stops, paths) AS ( "
+ "SELECT sname, snext, 1 stops, "
+ " CAST(concat(sline,sname,'->',sline,snext) AS char(1000)) AS paths "
+ "FROM biejing_subway "
+ "WHERE sname = '"+startname+"' "
+ "UNION ALL "
+ "SELECT t.startname, s.snext, stops+1, concat(paths, '->', s.sline, s.snext) "
+ "FROM transfer t "
+ "JOIN biejing_subway s "
+ "ON (t.stopname = s.sname AND instr(paths, s.snext)=0) "
+ ") "
+ "SELECT * "
+ "FROM transfer "
+ "WHERE stopname = '"+stopname+"';";
Statement stmt= conn.createStatement();
ResultSet find=stmt.executeQuery(sql);
int s=0;
while(find.next()) {
anllrole[s]=new String();
anllrole[s]=find.getString(4);
temp[s]=find.getInt(3);
s++;
}
find.close();
stmt.close();
conn.close();
for(int j=0;anllrole[j]!=null;j++) {
int change=0;
char station='#';
System.out.println(anllrole[j]+"mmmmmmmmmmmmmmmmmmmmmmm");
roles=anllrole[j].toCharArray();
int lengths=roles.length;
for(int k=0;k<lengths-1;k++) {
if(k==0)station=roles[0];
if(roles[k]=='>') {
if(!(roles[k+1]==station)) {
change=change+1;
System.out.println(station+"qqqqqqqqq");
station=roles[k+1];
}
}
}
System.out.println(change+"lllllllllllllllllllllllll");
if(change<number) location=j;
}
return location;
}