Re: [問題] 動態調整深度的迴圈(loop)

看板C_and_CPP作者 (snowlike)時間16年前 (2009/10/29 14:07), 編輯推噓0(002)
留言2則, 1人參與, 最新討論串5/7 (看更多)
迴圈的; int max=4, input=5; int *args=new int[input]; for(int i=0; i<pow((double)max, input); ++i) { for(int j=input; j>0; --j) { args[input-j]=(int)(i/pow((double)max, j-1))%4; if(j!=input&&args[input-j-1]>args[input-j]) { ++i, ++j; } } for(int j=0; j<input; ++j) { cout<<" "<<args[j]; } cout<<endl; } delete[] args; -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 203.68.164.15

10/29 14:25, , 1F
別那麼愛用 pow .... 非常慢
10/29 14:25, 1F

10/29 14:26, , 2F
改成每次隨迴圈乘 max 好得多
10/29 14:26, 2F
文章代碼(AID): #1AwJ4qTf (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1AwJ4qTf (C_and_CPP)