Re: [問題] 動態調整深度的迴圈(loop)
看板C_and_CPP (C/C++)作者snowlike (snowlike)時間16年前 (2009/10/29 14:07)推噓0(0推 0噓 2→)留言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
10/29 14:25, 1F
→
10/29 14:26, , 2F
10/29 14:26, 2F
討論串 (同標題文章)
完整討論串 (本文為第 5 之 7 篇):
7
18
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章