Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- using namespace std;
- void printPartitions(int startValue, int target, int maxValue, string suffix) {
- if (target == 0) {
- suffix.erase(0,3);
- cout <<startValue<<" = "<< suffix << endl;
- } else {
- if (maxValue <= target) {
- ostringstream oss;
- oss << suffix << " + " << maxValue;
- string temp = oss.str();
- printPartitions(startValue, target - maxValue, maxValue, temp);
- }
- if (maxValue > 1) {
- printPartitions(startValue, target, maxValue - 1, suffix);
- }
- }
- }
- int main() {
- int n;
- cin >> n;
- printPartitions(n, n, n, "");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement