decomposing 10 cents (practice 2)"/>
Solve problem of decomposing 10 cents (practice 2)
Input the money you have:
10
1分 2分 5分
0 0 2
1 2 1
3 1 1
5 0 1
6 2 0
8 1 0
10 0 0
The codes:
#include <iostream>
using namespace std;
void decompose_to_changes(int n);
int main()
{cout << "Input the money you have:"<< endl;int n;cin >> n;decompose_to_changes(n);return 0;
}
void decompose_to_changes(int n)
{cout << "1分" << ' '<< "2分" << ' '<< "5分" << endl;int i, j, k;for(int i= 0; i<=n; ++i){for(int j =0; j<=n/5; ++j){for(int k =0; k<=n/2; ++k){if(i+2*j+5*k == n){cout << i<< " " << j<< " " << k<< endl;}}}}
}
Cconference:
(8条消息) 【算法】求解钱币兑换问题_H1519223775的博客-CSDN博客
更多推荐
Solve problem of decomposing 10 cents (practice 2)
发布评论