考慮下面的要求,設計出一個公式來尋找X和Y以下設計一個循環中的公式爲x和y滿足這些要求
given: length1 length2, assume length1 >= length2
total = length1 + length2
i = 0 : x = 0, y = 0
i = 1 : x = 0, y = 1
...
i = length2 -1 : x = 0, y = length2 -1
i = total-length1 : x = 0, y = 0
i = total-length1 +1 : x = 1, y = 0
...
i = length1 + length2: x = length1 -1, y = 0
所以在代碼給出,它看起來是這樣的:
int length1 = //given
int length2 = //given
int total = length1 + length2;
for (int i = 0; i < total; i++) {
x = ? //answer here
y = ? //answer here
}
這裏是length1 = 5的例子;長度2 = 4
i x,y
---------
i=0 0,0
i=1 0,1
i=2 0,2
i=3 0,3
i=4 0,0
i=5 1,0
i=6 2,0
i=7 3,0
i=8 4,0
編輯: 我正在尋找一個1班輪尋找x和y。
當i> length1時,當i小於length2時y將x分成0,當y爲0時x將分成0。
爲什麼所有的下跌票和關閉投票? – Dani