tabuList[i][j]-=tabuList[i][j]<=0?0:1;
可以寫爲:
int tabuListEntry = tabuList[i][j];
tabuListEntry -=tabuListEntry <=0?0:1;
可以寫爲:
int tabuListEntry = tabuList[i][j];
tabuListEntry = tabuListEntry - (tabuListEntry <=0?0:1);
可以寫爲:
int tabuListEntry = tabuList[i][j];
int decrementAmount = tabuListEntry <=0?0:1;
tabuListEntry = tabuListEntry - decrementAmount ;
可以寫爲:
int tabuListEntry = tabuList[i][j];
int decrementAmount = 0;
if(tabuListEntry <= 0) {
decrementAmount = 0;
} else {
decrementAmount = 1;
}
tabuListEntry = tabuListEntry - decrementAmount ;
可以寫爲:
int tabuListEntry = tabuList[i][j];
int decrementAmount = 0;
if(tabuListEntry > 0) {
decrementAmount = 1;
}
tabuListEntry = tabuListEntry - decrementAmount ;
可以寫爲:
int tabuListEntry = tabuList[i][j];
if(tabuListEntry > 0) {
tabuListEntry = tabuListEntry - 1;
}
這是一個if/then查詢的簡寫形式:(tabuList [i] [j] <= 0)? 0:1。這意味着如果tabuList [i] [j]中的值小於0,則減去0,否則減1。問號以某種方式替代如果並且冒號代替其他。 –
基本上要求作業的幫助,快速瀏覽任何教程或語言書籍將顯示。 – jwenting
這是舊的,但這隻適用於方陣。第二個for循環應該是「for(int j = 0; j