我假定了10条线路,button1的作用是起点到终点坐一条线直达,button2的作用是需换车的,但是button2有错误,运行不出来。(textBox1是起点,textBox2是终点)using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace bus_station
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string[] bus = new string[10]; private void button1_Click(object sender, EventArgs e)
{
string path = " ";
string aa = " ";
for (int i = 0; i < bus.Length; i++)
{
aa = bus[i];
if ((aa.IndexOf(textBox1.Text) >= 0) && (aa.IndexOf(textBox2.Text) >= 0))
{
string[] b = aa.Split(',');
path += b[0];
}
}
if (path != " ") textBox3.Text = path;
else textBox3.Text = "没有合适的线路"; }
private string tr(string a, string b)
{
string ret = " ";
string[] a1 = a.Split(',');
string[] b1 = b.Split(',');
for (int i = 0; i < a1.Length; i++)
{
for (int j = 0; j < b1.Length; j++)
{
if (a1[i] == b1[j])
{
if (ret == " ") ret = a1[i]; else ret += "," + a1[i];
}
}
}
return ret;
}
private void button2_Click(object sender, EventArgs e)
{
string path = " ";
string aa = " ", bb = " ",cc=" ";
for (int i = 0; i <bus.Length; i++)
{
aa = bus[i];
if (aa.IndexOf(textBox1.Text) >= 0)
{
for (int j = 0; j < bus.Length; j++)
if (i != j)
{
bb = bus[j];
if (bb.IndexOf(textBox2.Text) >= 0)
{
cc = tr(aa, bb);
if (cc != " ")
path += aa.Substring(0, 4) + "→" + cc+"转" + bb.Substring(0, 4) + "→" + textBox2.Text;
}
}
}
}
if (path != " ") textBox3.Text = path;
else textBox3.Text = "没有合适的线路"; } private void Form1_Load(object sender, EventArgs e)
{
bus[0] = "#1,10,11,12,13,14,15,16,17,18,19";
bus[1] = "#2,20,21,22,23,24,25,26,27,28,29";
bus[2] = "#3,30,31,32,33,34,35,36,37,38,39";
bus[3] = "#4,40,41,42,43,44,45,46,47,48,49";
bus[4] = "#5,50,51,52,53,54,55,56,57,58,59";
bus[5] = "#6,60,61,62,63,64,65,66,67,68,69";
bus[6] = "#7,70,71,12,73,74,75,76,77,78,79";
bus[7] = "#8,80,81,82,83,84,85,86,87,88,89";
bus[8] = "#9,90,91,92,93,94,95,96,97,98,99";
bus[9] = "#10,00,01,02,03,04,05,06,07,08,09";
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace bus_station
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string[] bus = new string[10]; private void button1_Click(object sender, EventArgs e)
{
string path = " ";
string aa = " ";
for (int i = 0; i < bus.Length; i++)
{
aa = bus[i];
if ((aa.IndexOf(textBox1.Text) >= 0) && (aa.IndexOf(textBox2.Text) >= 0))
{
string[] b = aa.Split(',');
path += b[0];
}
}
if (path != " ") textBox3.Text = path;
else textBox3.Text = "没有合适的线路"; }
private string tr(string a, string b)
{
string ret = " ";
string[] a1 = a.Split(',');
string[] b1 = b.Split(',');
for (int i = 0; i < a1.Length; i++)
{
for (int j = 0; j < b1.Length; j++)
{
if (a1[i] == b1[j])
{
if (ret == " ") ret = a1[i]; else ret += "," + a1[i];
}
}
}
return ret;
}
private void button2_Click(object sender, EventArgs e)
{
string path = " ";
string aa = " ", bb = " ",cc=" ";
for (int i = 0; i <bus.Length; i++)
{
aa = bus[i];
if (aa.IndexOf(textBox1.Text) >= 0)
{
for (int j = 0; j < bus.Length; j++)
if (i != j)
{
bb = bus[j];
if (bb.IndexOf(textBox2.Text) >= 0)
{
cc = tr(aa, bb);
if (cc != " ")
path += aa.Substring(0, 4) + "→" + cc+"转" + bb.Substring(0, 4) + "→" + textBox2.Text;
}
}
}
}
if (path != " ") textBox3.Text = path;
else textBox3.Text = "没有合适的线路"; } private void Form1_Load(object sender, EventArgs e)
{
bus[0] = "#1,10,11,12,13,14,15,16,17,18,19";
bus[1] = "#2,20,21,22,23,24,25,26,27,28,29";
bus[2] = "#3,30,31,32,33,34,35,36,37,38,39";
bus[3] = "#4,40,41,42,43,44,45,46,47,48,49";
bus[4] = "#5,50,51,52,53,54,55,56,57,58,59";
bus[5] = "#6,60,61,62,63,64,65,66,67,68,69";
bus[6] = "#7,70,71,12,73,74,75,76,77,78,79";
bus[7] = "#8,80,81,82,83,84,85,86,87,88,89";
bus[8] = "#9,90,91,92,93,94,95,96,97,98,99";
bus[9] = "#10,00,01,02,03,04,05,06,07,08,09";
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货