写个算法
string[] B= new string[7]{"A","B","C","D","E","F","G"};
string[] A= new string[3]{"a","b","c"}; //a最多发送两次
AB是一一对应的,在两者数量不等的情况下,要依次对应,如果a发送超过两次则自动跳过。
最终结果 a_A,b_B,c_C,a_D,b_E,c_F,b_G 算法
[解决办法]
string[] B = new string[7] { "A", "B", "C", "D", "E", "F", "G" };
string[] A = new string[3] { "a", "b", "c" }; //a最多发送两次
for (int i = 0; i < B.Length; i++)
{
if (i / A.Length < 1)
{
MessageBox.Show("" + A[i] + "_" + B[i] + "");
}
else if (i / A.Length >= 1 && i / A.Length < 2)
{
MessageBox.Show("" + A[i - A.Length] + "_" + B[i] + "");
}
else
MessageBox.Show("" + A[i - 2*A.Length+1] + "_" + B[i] + "");
}
string[] B = new string[13] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M" };
string[] A = new string[3] { "a", "b", "c" }; //a最多发送两次
List<string> lstResult = new List<string>();
int index = 0, aCount = 0, aLength = A.Length, bLength = B.Length;
string result = string.Empty;
for (int i = 0; i < bLength; i++)
{
index = index % aLength;
result = A[index] + "_" + B[i];
if (A[index] == "a")
{
if (++aCount > 2)
{
result = A[++index] + "_" + B[i];
}
}
/**添加判断a 2次, b 3次,。。。**/
lstResult.Add(result);
index++;
}