gpt4 book ai didi

c# - 打印 i,j 的每个值的输出

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:00:51 25 4
gpt4 key购买 nike

在下面属于 floyd 算法的代码中,我如何打印 i、j 的每个值的输出?例如最短距离 [0,0]=2 和最短 [0,1]=4 等现在它打印从 i 到 j 的最短距离是:3(例如)

private void button10_Click(object sender, EventArgs e)
{

string ab = textBox11.Text;
int matrixDimention = Convert.ToInt32(ab);
int[,] intValues = new int[matrixDimention, matrixDimention];
string[] splitValues = textBox9.Text.Split(',');

for (int i = 0; i < splitValues.Length; i++)
intValues[i / (matrixDimention), i % (matrixDimention)] = Convert.ToInt32(splitValues[i]);

string displayString = "";

for (int inner = 0; inner < intValues.GetLength(0); inner++)
{
for (int outer = 0; outer < intValues.GetLength(0); outer++)
displayString += String.Format("{0}\t", intValues[inner, outer]);

displayString += Environment.NewLine;
}

int n=matrixDimension

MessageBox.Show("matrix"+strn+ "in" + strn + "is\n\n\n" +displayString);

////before this line i wrote the codes to get the numbers that user enter in textbox and put it in an 2d array
for (int k = 0; k < n; k++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
if (intValues[i, j] > intValues[i, k] + intValues[k, j])
{
intValues[i, j] = intValues[i, k] + intValues[k, j];
string str_intvalues = intValues[i, j].ToString();
MessageBox.Show("Shortest Path from i to j is: " + str_intvalues);
}
else
{
string str_intvalues = intValues[i, j].ToString();
MessageBox.Show("Shortest Path from i to j is: " + str_intvalues);

}
}
}

最佳答案

我将 MessageBox.show() 都编辑为这种形式并更正了:

MessageBox.Show("Shortest distance from" + i + " to " + j + " isnnt: " + str_intvalues);

关于c# - 打印 i,j 的每个值的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4527285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com