再次递归思想-路劲跨越多个阵列
种类:
1. SHA-AA/BA/KX/WC-NYC/TYO/OSA-BA/NX/CX-NYC
2. SHA -NYC/TYO/OSA -NYC
/之间区分的长度不一
想要的结果SHA-AA-NYC-BA-NYC
SHA-AA-NYC-NX-NYC
SHA-AA-NYC-CX-NYC
SHA-AA-NYC-CX-NYC
SHA-AA-TYO-BA-NYC
SHA-AA- TYO-NX-NYC
SHA-AA- TYO-CX-NYC
SHA-AA- TYO-CX-NYC
第一条有排列组合36种
思路
private void button1_Click(object sender, EventArgs e) { string txtOrg = textBox1.Text.Trim(); string[] t1 = txtOrg.Split('-'); //if ((t1.Length & 1) != 1) //{ // MessageBox.Show("录入数据有问题"); // return; //} StringBuilder sb = new StringBuilder(""); GetStringRecursive(sb, "", t1.ToList()); textBox2.Text = "广告位招租。欲去除请付我5元钱\r\n" + sb.ToString(); } private string GetStringRecursive(StringBuilder preBf, string pre, List<string> listStr) { //List<string> listRet = new List<string>(); string retStr = ""; if(listStr.Count == 0) return pre + "\r\n"; else{ List<string> listTmp = listStr[0].Split('/').ToList(); List<string> listTmp2 = new List<string>(); for (int i = 1; i <= listStr.Count - 1; i++) listTmp2.Add(listStr[i]);
bool isOver = listTmp2.Count == 0; for (int i = 0; i <= listTmp.Count - 1; i++) { string strTmp = listTmp[i].Trim(); //string[] = strTmp[i] retStr = pre + strTmp; //listStr.Remove() if (isOver) { preBf.Append(retStr + "\r\n"); } else { GetStringRecursive(preBf, retStr + '-', listTmp2); } } } return retStr; }
版权声明:本文博主原创文章,博客,未经同意不得转载。