我是Mathematica的新手,看來我在Mathematica語法中缺少一些東西。我想將C代碼轉換爲Mathematica代碼,我做錯了什麼?
我在下面複製了兩個代碼。
列印[第二]必須返回120,用於本實施例中,但它始終是0。
任何建議表示讚賞。
C:
int row = 4;
int column = 10;
int passenger = 5;
int luggage = 20;
int arrival = 15;
int walking = 5;
int second = 0;
int waitingtime = 0;
int _yolcu = 0;
for (int i = 0; i <row; i++)
{
waitingtime = 0;
if (_yolcu == passenger)
break;
for (int j = 0; j < column; j++)
{
if (_yolcu == passenger)
break;
_yolcu++;
if (i == 0 && j == 0){
second = second + luggage;
continue;
}
else
{
waitingtime = 0;
waitingtime =second-(j * walking + arrival * (_yolcu - 1));
if (waitingtime>= 0)
{
second = second + walking + luggage;
}
else
second = second - waitingtime+luggage;
}
}
}
數學:
row = 4;
column = 10;
passenger = 5;
luggage = 20;
arrival = 15;
walking = 5;
second = 0;
waitingtime = 0;
_yolcu = 0;
For[i = 0, i < row, i++, waitingtime = 0;
If[_yolcu == passenger, Break[],
For[j = 0, j < column, j++,
If[_yolcu == passenger, Break[], _yolcu++;
If[i == 0 && j == 0, second = second + luggage,
waitingtime = second - (j*walking + arrival*(_yolcu - 1));
If[waitingtime >= 0, second = second + walking + luggage,
second = second - waitingtime + luggage]]]]]]
Print[second]
非常感謝,該下劃線導致我的問題。 – Burak