[請益] 求這段程式詳細的解釋

看板Programming作者 (睡神阿德)時間5年前 (2019/05/19 01:14), 編輯推噓1(102)
留言3則, 2人參與, 5年前最新討論串1/1
#include <iostream>using namespace std; int parts[101]; void Partition(int limit, int now, int pointer) { if (now < 0) return; if (!now) { for (int i = 0; i < pointer; i++) cout << parts[i] << ' '; cout << '\n'; return; } for (int i = limit; i >= 1; i--) parts[pointer] = i, Partition(i, now - i, pointer + 1); } int main() { int number; cin.sync_with_stdio(false), cin.tie(0), cout.tie(0); while (cin >> number) Partition(number, number, 0); } --------------------------------------------------------- 這是C++的程式碼, 由於要用其他程式做題目, 所以查了C++的, 但是沒學過, 即便這陣子惡補了一下還是看無, 我要做的事情是整數分割, 有人能解釋一下它的邏輯嗎? 會一句是一句, 謝謝大家 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.250.226.72 ※ 文章網址: https://www.ptt.cc/bbs/Programming/M.1558199690.A.B02.html

05/19 02:12, 5年前 , 1F
既然你看程式碼有問題的話就別找程式碼
05/19 02:12, 1F

05/19 02:12, 5年前 , 2F
找"演算法"才是你要的
05/19 02:12, 2F

05/21 04:30, 5年前 , 3F
請洽codejob版
05/21 04:30, 3F
文章代碼(AID): #1Su3sAi2 (Programming)