Solve problem of decomposing 10 cents (practice 2)

编程入门 行业动态 更新时间:2024-10-26 17:32:27

Solve problem of <a href=https://www.elefans.com/category/jswz/34/1106975.html style=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)

本文发布于:2024-03-13 09:15:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1733644.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:decomposing   problem   Solve   practice   cents

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!