码迷,mamicode.com
首页 > 其他好文 > 详细

石家庄地铁(李秦,王学云)

时间:2019-04-04 00:06:47      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:tco   ted   jdb   i+1   nod   ica   function   add   on()   

bean包:

package subway.bean;

public class Subway {
    private int Id;
    private String Sname;
    private String Snum;
    
    private String Change;
    public Subway(int id2, String sname2, String snum2, String change2) 
    {
        this.Id=id2;
        this.Sname=sname2;
        this.Snum=snum2;
        this.Change=change2;

    }
    public String getSname() {
        return Sname;
    }
    public void setSname(String sname) {
        Sname = sname;
    }
    public String getSnum() {
        return Snum;
    }
    public void setSnum(String snum) {
        Snum = snum;
    }
    public int getId() {
        return Id;
    }
    public void setId(int id) {
        Id = id;
    }
    public String getChange() {
        return Change;
    }
    public void setChange(String change) {
        Change = change;
    }


}

dao包

package subway.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import subway.bean.Subway;
import subway.util.BaseConnection;

public class Dao {
    /*public static void main(String[] args)
    {
        String start;
        String end;
        Scanner in=new Scanner(System.in);
        start=in.next();
        end=in.next();
        System.out.println(start);
        System.out.println(end);
        List<Subway> list_1=list("first");
        List<Subway> list_2=list("second");
        List<Subway> list_3=list("third");
        List<Subway> list_4=list("fourth");
        List<Subway> list_5=list("fifth");
        List<Subway> list_6=list("sixth");
        List<Subway> change_1=findChange("first");
        List<Subway> change_2=findChange("second");
        List<Subway> change_3=findChange("third");
        List<Subway> change_4=findChange("fourth");
        List<Subway> change_5=findChange("fifth");
        List<Subway> change_6=findChange("sixth");
        List<Subway> listGather=Gather(list_1,list_2,list_3,list_4,list_5,list_6);
        List<Subway> listchange=Gather(change_1,change_2,change_3,change_4,change_5,change_6);
        List<Subway> Startlist=CheckStartEnd(start,listGather);
        List<Subway> Endlist=CheckStartEnd(end,listGather);
        List<List<Subway>> result=Judge(Endlist, Startlist, listGather, listchange);
        List<Subway> MinShort=new ArrayList();
        List<Subway> MinChange=new ArrayList();
        int shortline=0;
        for(int i=0;i<result.size()-1;i++)//??????·??
        {
            if(result.get(i).size()>result.get(i+1).size())
            {
                shortline=i+1;
            }
        }
        MinShort=result.get(shortline);
        int[] shortchange=new int[result.size()];
        for(int i=0;i<result.size();i++)
        {
            shortchange[i]=0;
            for(int t=0;t<result.get(i).size();t++)
            {
                if(result.get(i).get(t).getChange()!=null)
                {
                    shortchange[i]++;
                }
            }
        }
        int shortmin=0;
        for(int i=0;i<result.size()-1;i++)
        {
            if(shortchange[i]>shortchange[i+1])
            {
                shortmin=i+1;
            }
        }
        MinChange=result.get(shortmin);
        System.out.println("?????·??");
        for(int i=0;i<MinShort.size();i++)
        {
            System.out.println(MinShort.get(i).getSname());
        }
        System.out.println("????????");
        for(int i=0;i<MinChange.size();i++)
        {
            System.out.println(MinChange.get(i).getSname());
        }
    }*/
    public static List<Subway> list(String table) {
        String sql = "select * from " +table;
        List<Subway> list = new ArrayList<>();
        Connection conn = BaseConnection.getConnection();
        Statement state = null;
        ResultSet rs = null;

        try {
            state = conn.createStatement();
            rs = state.executeQuery(sql);
            Subway subway = null;
            while (rs.next()) {
                
                String Sname = rs.getString("Sname");
                String Snum = rs.getString("Snum");
                int Id = rs.getInt("Id");
                String Change = rs.getString("Change1");
                subway = new Subway(Id, Sname, Snum, Change);
                list.add(subway);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            BaseConnection.close(rs, state, conn);
        }
        
        return list;
    }
    public static List<List<Subway>> Judge(List<Subway> Endlist,List<Subway> Startlist,List<Subway> listGather,List<Subway> listchange)
    {
        List<List<Subway>> result=new ArrayList();
        for(int k=0;k<Startlist.size();k++)
        {
            for(int h=0;h<Endlist.size();h++)
//        if(Startlist.size()==1&&Endlist.size()==1)
        {
            Subway waystart=Startlist.get(k);
            Subway wayend=Endlist.get(h);
            if(waystart.getSnum().equals(wayend.getSnum()))//?????
            {
                List<Subway> num0=new ArrayList();
                if(waystart.getId()>=wayend.getId())
                {
                    for(int n=listGather.size()-1;n>=0;n--)
                    {
                        if(listGather.get(n).getSnum().equals(waystart.getSnum()))
                        {
                            if(listGather.get(n).getId()<=waystart.getId()&&listGather.get(n).getId()>=wayend.getId())
                            {
                                num0.add(listGather.get(n));
                            }
                        }
                    }
                    result.add(num0);
                }
                if(waystart.getId()<wayend.getId())
                {
                    for(int n=0;n<listGather.size();n++)
                    {
                        if(listGather.get(n).getSnum().equals(waystart.getSnum()))
                        {
                            if(listGather.get(n).getId()>=waystart.getId()&&listGather.get(n).getId()<=wayend.getId())
                            {
                                num0.add(listGather.get(n));
                            }
                        }
                    }
                    result.add(num0);
                }
            }
            for(int i=0;i<listchange.size();i++)
            {
                if(listchange.get(i).getSnum().equals(waystart.getSnum()))
                {
                    if(listchange.get(i).getChange().equals(wayend.getSnum()))//??????
                    {
                        List<Subway> num1=new ArrayList();
                        for(int e1=0;e1<listchange.size();e1++)
                        {
                            if(listchange.get(i).getSname().equals(listchange.get(e1).getSname())&&!listchange.get(i).getSnum().equals(listchange.get(e1).getSnum()))//??û??????????·
                            {
                                if(listchange.get(i).getId()>waystart.getId()&&listchange.get(e1).getId()<wayend.getId())
                                {
                                    for(int n1=0;n1<listGather.size();n1++)
                                    {
                                        if(listGather.get(n1).getSnum().equals(waystart.getSnum()))
                                        {
                                            if(listGather.get(n1).getId()>=waystart.getId()&&listGather.get(n1).getId()<=listchange.get(i).getId())
                                            {
                                                num1.add(listGather.get(n1));
                                            }
                                        }
                                    }
                                    for(int n1=0;n1<listGather.size();n1++)
                                    {
                                        if(listGather.get(n1).getSnum().equals(wayend.getSnum()))
                                        {
                                            if(listGather.get(n1).getId()>listchange.get(e1).getId()&&listGather.get(n1).getId()<=wayend.getId())
                                            {
                                                num1.add(listGather.get(n1));
                                            }
                                        }
                                    }
                                    result.add(num1);
        
                                }
                                if(listchange.get(i).getId()<waystart.getId()&&listchange.get(e1).getId()<wayend.getId())
                                {
                                    for(int n1=listGather.size()-1;n1>=0;n1--)
                                    {
                                        if(listGather.get(n1).getSnum().equals(waystart.getSnum()))
                                        {
                                            if(listGather.get(n1).getId()<=waystart.getId()&&listGather.get(n1).getId()>=listchange.get(i).getId())
                                            {
                                                num1.add(listGather.get(n1));
                                            }
                                        }
                                    }
                                    for(int n1=0;n1<listGather.size();n1++)
                                    {
                                        if(listGather.get(n1).getSnum().equals(wayend.getSnum()))
                                        {
                                            if(listGather.get(n1).getId()>listchange.get(e1).getId()&&listGather.get(n1).getId()<=wayend.getId())
                                            {
                                                num1.add(listGather.get(n1));
                                            }
                                            
                                        }
                                    }
                                    result.add(num1);
                                }
                                if(listchange.get(i).getId()<waystart.getId()&&listchange.get(e1).getId()>wayend.getId())
                                {
                                    for(int n1=listGather.size()-1;n1>=0;n1--)
                                    {
                                        if(listGather.get(n1).getSnum().equals(waystart.getSnum()))
                                        {
                                            if(listGather.get(n1).getId()<=waystart.getId()&&listGather.get(n1).getId()>=listchange.get(i).getId())
                                            {
                                                num1.add(listGather.get(n1));
                                            }
                                        }
                                    }
                                    for(int n1=listGather.size()-1;n1>=0;n1--)
                                    {
                                        if(listGather.get(n1).getSnum().equals(wayend.getSnum()))
                                        {
                                            if(listGather.get(n1).getId()<listchange.get(e1).getId()&&listGather.get(n1).getId()>=wayend.getId())
                                            {
                                                num1.add(listGather.get(n1));
                                            }
                                            
                                        }
                                    }
                                    result.add(num1);
                                }
                                if(listchange.get(i).getId()>waystart.getId()&&listchange.get(e1).getId()>wayend.getId())
                                {
                                    for(int n1=0;n1<listGather.size();n1++)
                                    {
                                        if(listGather.get(n1).getSnum().equals(waystart.getSnum()))
                                        {
                                            if(listGather.get(n1).getId()>=waystart.getId()&&listGather.get(n1).getId()<=listchange.get(i).getId())
                                            {
                                                num1.add(listGather.get(n1));
                                            }
                                        }
                                    }
                                    for(int n1=listGather.size()-1;n1>=0;n1--)
                                    {
                                        if(listGather.get(n1).getSnum().equals(wayend.getSnum()))
                                        {
                                            if(listGather.get(n1).getId()<listchange.get(e1).getId()&&listGather.get(n1).getId()>=wayend.getId())
                                            {
                                                num1.add(listGather.get(n1));
                                            }
                                            
                                        }
                                    }
                                    result.add(num1);
                                }
                            }
                        }
                    }
                    if(!listchange.get(i).getChange().equals(wayend.getSnum()))//??????
                    {
                        List<Subway> num2=new ArrayList();
                        for(int e1=0;e1<listchange.size();e1++)
                        {
                            if(listchange.get(i).getSname().equals(listchange.get(e1).getSname())&&!listchange.get(i).getSnum().equals(listchange.get(e1).getSnum()))//??ý?????????????·
                            {
                                for(int t1=0;t1<listchange.size();t1++)
                                {
                                    if(listchange.get(e1).getSnum().equals(listchange.get(t1).getSnum())&&!listchange.get(e1).getSname().equals(listchange.get(t1).getSname()))//??û?????????
                                    {
                                        if(listchange.get(t1).getChange().equals(wayend.getSnum()))//????????λ??
                                        {
                                            for(int t2=0;t2<listchange.size();t2++)
                                            {
                                                if(listchange.get(t1).getSname().equals(listchange.get(t2).getSname())&&!listchange.get(t1).getSnum().equals(listchange.get(t2).getSnum()))
                                                {
                                                    if(listchange.get(i).getId()>waystart.getId()&&listchange.get(e1).getId()>listchange.get(t1).getId()&&listchange.get(t2).getId()>wayend.getId())
                                                        //> > >
                                                    {
                                                        num2=new ArrayList();
                                                        for(int n1=0;n1<listGather.size();n1++)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(waystart.getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()>=waystart.getId()&&listGather.get(n1).getId()<=listchange.get(i).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        for(int n1=listGather.size()-1;n1>=0;n1--)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(listchange.get(e1).getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()>=listchange.get(t1).getId()&&listGather.get(n1).getId()<listchange.get(e1).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        for(int n1=listGather.size()-1;n1>=0;n1--)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(listchange.get(t2).getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()>=wayend.getId()&&listGather.get(n1).getId()<listchange.get(t2).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        result.add(num2);                                                        System.out.println("");
                                                    }
                                                    if(listchange.get(i).getId()<waystart.getId()&&listchange.get(e1).getId()>listchange.get(t1).getId()&&listchange.get(t2).getId()>wayend.getId())
                                                        //< > >
                                                    {
                                                        num2=new ArrayList();
                                                        for(int n1=listGather.size()-1;n1>=0;n1--)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(waystart.getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()<=waystart.getId()&&listGather.get(n1).getId()>=listchange.get(i).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        for(int n1=listGather.size()-1;n1>=0;n1--)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(listchange.get(e1).getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()>=listchange.get(t1).getId()&&listGather.get(n1).getId()<listchange.get(e1).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        for(int n1=listGather.size()-1;n1>=0;n1--)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(listchange.get(t2).getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()>=wayend.getId()&&listGather.get(n1).getId()<listchange.get(t2).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        result.add(num2);                                                        System.out.println("");
                                                    }
                                                    if(listchange.get(i).getId()>waystart.getId()&&listchange.get(e1).getId()<listchange.get(t1).getId()&&listchange.get(t2).getId()>wayend.getId())
                                                        //> < >
                                                    {
                                                        num2=new ArrayList();
                                                        for(int n1=0;n1<listGather.size();n1++)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(waystart.getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()>=waystart.getId()&&listGather.get(n1).getId()<=listchange.get(i).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        for(int n1=0;n1<listGather.size();n1++)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(listchange.get(e1).getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()<=listchange.get(t1).getId()&&listGather.get(n1).getId()>listchange.get(e1).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        for(int n1=listGather.size()-1;n1>=0;n1--)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(listchange.get(t2).getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()>=wayend.getId()&&listGather.get(n1).getId()<listchange.get(t2).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        result.add(num2);                                                        System.out.println("");
                                                    }
                                                    if(listchange.get(i).getId()>waystart.getId()&&listchange.get(e1).getId()>listchange.get(t1).getId()&&listchange.get(t2).getId()<wayend.getId())
                                                        //> > <
                                                    {
                                                        num2=new ArrayList();
                                                        for(int n1=0;n1<listGather.size();n1++)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(waystart.getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()>=waystart.getId()&&listGather.get(n1).getId()<=listchange.get(i).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        for(int n1=listGather.size()-1;n1>=0;n1--)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(listchange.get(e1).getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()>=listchange.get(t1).getId()&&listGather.get(n1).getId()<listchange.get(e1).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        for(int n1=0;n1<listGather.size();n1++)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(listchange.get(t2).getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()<=wayend.getId()&&listGather.get(n1).getId()>listchange.get(t2).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        result.add(num2);                                                        System.out.println("");
                                                    }
                                                    if(listchange.get(i).getId()<waystart.getId()&&listchange.get(e1).getId()<listchange.get(t1).getId()&&listchange.get(t2).getId()>wayend.getId())
                                                        //< < >
                                                    {
                                                        num2=new ArrayList();
                                                        for(int n1=listGather.size()-1;n1>=0;n1--)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(waystart.getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()<=waystart.getId()&&listGather.get(n1).getId()>=listchange.get(i).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        for(int n1=0;n1<listGather.size();n1++)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(listchange.get(e1).getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()<=listchange.get(t1).getId()&&listGather.get(n1).getId()>listchange.get(e1).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        for(int n1=listGather.size()-1;n1>=0;n1--)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(listchange.get(t2).getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()>=wayend.getId()&&listGather.get(n1).getId()<listchange.get(t2).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        result.add(num2);                                                        System.out.println("");
                                                    }
                                                    if(listchange.get(i).getId()<waystart.getId()&&listchange.get(e1).getId()>listchange.get(t1).getId()&&listchange.get(t2).getId()<wayend.getId())
                                                        //< > <
                                                    {
                                                        num2=new ArrayList();
                                                        for(int n1=listGather.size()-1;n1>=0;n1--)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(waystart.getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()<=waystart.getId()&&listGather.get(n1).getId()>=listchange.get(i).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        for(int n1=listGather.size()-1;n1>=0;n1--)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(listchange.get(e1).getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()>=listchange.get(t1).getId()&&listGather.get(n1).getId()<listchange.get(e1).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        for(int n1=0;n1<listGather.size();n1++)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(listchange.get(t2).getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()<=wayend.getId()&&listGather.get(n1).getId()>listchange.get(t2).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        result.add(num2);                                                        System.out.println("");
                                                    }
                                                    if(listchange.get(i).getId()>waystart.getId()&&listchange.get(e1).getId()<listchange.get(t1).getId()&&listchange.get(t2).getId()<wayend.getId())
                                                        //> < <
                                                    {
                                                        num2=new ArrayList();
                                                        for(int n1=0;n1<listGather.size();n1++)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(waystart.getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()>=waystart.getId()&&listGather.get(n1).getId()<=listchange.get(i).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        for(int n1=0;n1<listGather.size();n1++)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(listchange.get(e1).getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()<=listchange.get(t1).getId()&&listGather.get(n1).getId()>listchange.get(e1).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        for(int n1=0;n1<listGather.size();n1++)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(listchange.get(t2).getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()<=wayend.getId()&&listGather.get(n1).getId()>listchange.get(t2).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        result.add(num2);                                                        System.out.println("");
                                                    }
                                                    if(listchange.get(i).getId()<waystart.getId()&&listchange.get(e1).getId()<listchange.get(t1).getId()&&listchange.get(t2).getId()<wayend.getId())
                                                        //< < <
                                                    {
                                                        num2=new ArrayList();
                                                        for(int n1=listGather.size()-1;n1>=0;n1--)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(waystart.getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()<=waystart.getId()&&listGather.get(n1).getId()>=listchange.get(i).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        for(int n1=0;n1<listGather.size();n1++)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(listchange.get(e1).getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()<=listchange.get(t1).getId()&&listGather.get(n1).getId()>listchange.get(e1).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        for(int n1=0;n1<listGather.size();n1++)
                                                        {
                                                            if(listGather.get(n1).getSnum().equals(listchange.get(t2).getSnum()))
                                                            {
                                                                if(listGather.get(n1).getId()<wayend.getId()&&listGather.get(n1).getId()>listchange.get(t2).getId())
                                                                {
                                                                    num2.add(listGather.get(n1));                                                                    System.out.print(listGather.get(n1).getSname()+"->");
                                                                }
                                                            }
                                                        }
                                                        result.add(num2);
                                                    }
                                                    
                                                    
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        }
        return result;
    }
    public static List<Subway> CheckStartEnd(String startend,List<Subway> list)
    {
        Subway sub=null;
        List<Subway> StartEndlist=new ArrayList();
        for(int i=0;i<list.size();i++)
        {
            sub=list.get(i);
            if(sub.getSname().equals(startend))
            {
                StartEndlist.add(sub);
            }

            
        }
        return StartEndlist;
    }
    @SuppressWarnings("null")
    public static List<Subway> Gather(List<Subway> list1,List<Subway> list2,List<Subway> list3
            ,List<Subway> list4,List<Subway> list5,List<Subway> list6)
    {
        List<Subway> list =new ArrayList();
        Subway sub=null;
        list.addAll(list1);
        list.addAll(list2);
        list.addAll(list3);
        list.addAll(list4);
        list.addAll(list5);
        list.addAll(list6);
        return list;
    }
    public static List<Subway> findChange(String table)
    {
        
        String sql = "select * from "+ table +" where Change1 is not null";
        List<Subway> list = new ArrayList<>();
        Connection conn = BaseConnection.getConnection();
        Statement state = null;
        ResultSet rs = null;

        try {
            state = conn.createStatement();
            rs = state.executeQuery(sql);
            Subway subway = null;
            while (rs.next()) {
                int Id = rs.getInt("Id");
                String Sname = rs.getString("Sname");
                String Snum = rs.getString("Snum");
                String Change1 = rs.getString("Change1");
                subway = new Subway(Id, Sname, Snum, Change1);
                list.add(subway);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            BaseConnection.close(rs, state, conn);
        }
        return list;
    }

}

servlet包

package subway.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
//import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import subway.bean.Subway;
import subway.dao.*;
/**
 * Servlet implementation class Servlet
 */
//@WebServlet("/Servlet")
public class Servlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Servlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
    {
        request.setCharacterEncoding("UTF-8");
        String start=request.getParameter("start");
        String end=request.getParameter("end");
        Dao dao=new Dao();
        System.out.println(start);
        System.out.println(end);
        List<Subway> list_1=dao.list("first");
        List<Subway> list_2=dao.list("second");
        List<Subway> list_3=dao.list("third");
        List<Subway> list_4=dao.list("fourth");
        List<Subway> list_5=dao.list("fifth");
        List<Subway> list_6=dao.list("sixth");
        List<Subway> change_1=dao.findChange("first");
        List<Subway> change_2=dao.findChange("second");
        List<Subway> change_3=dao.findChange("third");
        List<Subway> change_4=dao.findChange("fourth");
        List<Subway> change_5=dao.findChange("fifth");
        List<Subway> change_6=dao.findChange("sixth");
        List<Subway> listGather=dao.Gather(list_1,list_2,list_3,list_4,list_5,list_6);
        List<Subway> listchange=dao.Gather(change_1,change_2,change_3,change_4,change_5,change_6);
        List<Subway> Startlist=dao.CheckStartEnd(start,listGather);
        List<Subway> Endlist=dao.CheckStartEnd(end,listGather);
        List<List<Subway>> result=dao.Judge(Endlist, Startlist, listGather, listchange);
        List<Subway> MinShort=new ArrayList();
        List<Subway> MinChange=new ArrayList();
        int shortline=0;
        for(int i=0;i<result.size()-1;i++)//??????·??
        {
            if(result.get(i).size()>result.get(i+1).size())
            {
                shortline=i+1;
            }
        }
        MinShort=result.get(shortline);
        int[] shortchange=new int[result.size()];
        for(int i=0;i<result.size();i++)
        {
            shortchange[i]=0;
            for(int t=0;t<result.get(i).size();t++)
            {
                if(result.get(i).get(t).getChange()!=null)
                {
                    shortchange[i]++;
                }
            }
        }
        int shortmin=0;
        for(int i=0;i<result.size()-1;i++)
        {
            if(shortchange[i]>shortchange[i+1])
            {
                shortmin=i+1;
            }
        }
        MinChange=result.get(shortmin);
        System.out.println("?????·??");
        for(int i=0;i<MinShort.size();i++)
        {
            System.out.println(MinShort.get(i).getSname());
        }
        System.out.println("????????");
        for(int i=0;i<MinChange.size();i++)
        {
            System.out.println(MinChange.get(i).getSname());
        }
        request.setAttribute("MinChange", MinChange);
        request.setAttribute("MinShort", MinShort);
        request.getRequestDispatcher("find.jsp").forward(request,response);

            
        
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

util包

package subway.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class BaseConnection {
    public static String db_url = "jdbc:mysql://localhost:3306/subway1";
    public static String db_user = "root";
    public static String db_password = "root";

    public static Connection getConnection() {
        Connection conn = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection(db_url, db_user, db_password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }
    
    public static void close(Statement state, Connection conn) {
        if(state!=null) {
            try {
                state.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(conn!=null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    
    public static void close(ResultSet rs, Statement state, Connection conn) {
        if(rs!=null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(state!=null) {
            try {
                state.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(conn!=null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

}

find.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>可控制图片放大缩小还原移动效果的JS网页图片查看器</title>
<meta http-equiv="imagetoolbar" content="no">
<style type="text/css">
    body
    {
        font-family: "Verdana" , "Arial" , "Helvetica" , "sans-serif";
        font-size: 12px;
        line-height: 180%;
    }
    td
    {
        font-size: 12px;
        line-height: 150%;
    }
</style>
<script language="JavaScript">
    drag = 0
    move = 0
 
    // 拖拽对象
    // 参见:http://blog.sina.com.cn/u/4702ecbe010007pe
    var ie = document.all;
    var nn6 = document.getElementById && !document.all;
    var isdrag = false;
    var y, x;
    var oDragObj;
 
    function moveMouse(e) {
        if (isdrag) {
            oDragObj.style.top = (nn6 ? nTY + e.clientY - y : nTY + event.clientY - y) + "px";
            oDragObj.style.left = (nn6 ? nTX + e.clientX - x : nTX + event.clientX - x) + "px";
            return false;
        }
    }
 
    function initDrag(e) {
        var oDragHandle = nn6 ? e.target : event.srcElement;
        var topElement = "HTML";
        while (oDragHandle.tagName != topElement && oDragHandle.className != "dragAble") {
            oDragHandle = nn6 ? oDragHandle.parentNode : oDragHandle.parentElement;
        }
        if (oDragHandle.className == "dragAble") {
            isdrag = true;
            oDragObj = oDragHandle;
            nTY = parseInt(oDragObj.style.top + 0);
            y = nn6 ? e.clientY : event.clientY;
            nTX = parseInt(oDragObj.style.left + 0);
            x = nn6 ? e.clientX : event.clientX;
            document.onmousemove = moveMouse;
            return false;
        }
    }
    document.onmousedown = initDrag;
    document.onmouseup = new Function("isdrag=false");
 
    
 
    function smallit() {
        var height1 = images1.height;
        var width1 = images1.width;
        images1.height = height1 / 1.2;
        images1.width = width1 / 1.2;
    }
 
    function bigit() {
        var height1 = images1.height;
        var width1 = images1.width;
        images1.height = height1 * 1.2;
        images1.width = width1 * 1.2;
    }
    function realsize() {
        images1.height = images2.height / 1.6; 
        images1.width = images2.width / 1.6;
        block1.style.left = 0;
        block1.style.top = 0;
 
    }
 
    window.onload = function () {
        var height1 = document.body.clientHeight;
        var width1 = document.body.clientWidth;
        images1.height = height1 ;
        images1.width = width1;
    }
 
 
 
</script>

<style type="text/css">

td, a { font-size:12px; color:#000000 }
#Layer1 { position:absolute; z-index:100; top: 10px;right: 5px;}
#Layer2 { position:absolute; z-index:1; }

.find{position: absolute;z-index: 10;font-size: 20;float:left}
.show{position: absolute;z-index: 20;font-size: 20;float:left;top:200px}

</style>
</head>

<body rightmargin="100" topmargin="0" marginwidth="0" marginheight="0" oncontextmenu="return false"
    ondragstart="return false" onselectstart="return false" onselect="document.selection.empty()"
    oncopy="document.selection.empty()" onbeforecopy="return false" onmouseup="document.selection.empty()"
    style="overflow-y: hidden; overflow-x: hidden;">
    <form action="${pageContext.request.contextPath}/Servlet" method="post">
    <div id="Layer1">

        <table border="0" cellspacing="2" cellpadding="5" >
           
            <tr>
                <td>
                </td>
                <td>
                    <img src="image/real.png" width="30" height="30" style="cursor: hand" onclick="realsize();"
                        title="还原" alert="还原">
                </td>
               
            </tr>
            
            <tr>
                <td>
                </td>
                <td>
                    <img src="image/big.png" width="30" height="30" style="cursor: hand" onclick="bigit();"
                        title="放大">
                </td>
                <td>
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                    <img src="image/small.png" width="30" height="30" style="cursor: hand" onclick="smallit();"
                        title="缩小">
                </td>
                <td>
                </td>
            </tr>
        </table>
    </div>
    <div id=‘hiddenPic‘ style=‘position: absolute; left: 0px; top: 0px; width: 0px; height: 0px;
        z-index: 1; visibility: hidden;‘>
        <img name=‘images2‘ src=‘image/1.jpg‘ border=‘0‘  />
    </div>
    <div id=‘block1‘ onmouseout=‘drag=0‘ onmouseover=‘dragObj=block1; drag=1;‘ style=‘z-index: 10;
        height: 0; left: 0px; position: absolute; top: 0px; width: 0‘ class="dragAble">
        <img name=‘images1‘ src=‘image/1.jpg‘ border=‘0‘ />
    </div>
    
    <div class="find">
            <h2 color="pink">
                换乘查询
            </h2>
            起始站:<input type="text" style="cursor: hand" name="start" ><br><br>
            终点站:<input type="text" style="cursor: hand" name="end" ><br><br>
            &nbsp&nbsp<input type="submit" value="提交" style="cursor: hand" margin="center">
            &nbsp&nbsp <input type="reset" value="重置">
        </div>
       
    <div class="show">
           <table>
            <c:forEach items="${MinShort}" var="item">
                <tr>
                    <td>${item.sname}</td>    
                    <td>${item.change}</td>                    
                </tr>
            </c:forEach>
            </table>
    </div>
</form>
</body>

</html>

 

石家庄地铁(李秦,王学云)

标签:tco   ted   jdb   i+1   nod   ica   function   add   on()   

原文地址:https://www.cnblogs.com/lq13035130506/p/10652422.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!