#include<iostream> //预操作
#include<cmath>
using namespace std;// 使用命名空间std
int main()
{
int i, j, k;
int sum = 0;
int a = 1, b = 2, c = 5;
cout << "The algorithms are :" << endl;
cout << "penny" << "\t" << "two cents" << "\t" << "five cents" << "\t" << endl;
for (i = 0; i <= 100; i++)
{
for (j = 0; j <=50; j++)
{
for (k = 20; k >= 0;k--)
{
if (100 == a*i + b*j + c*k)
{
cout << i << "\t" << j << "\t" << k << "\t" << endl;
sum++;
}
}
}
}
//命令提示符有字符限制,所以算法不能全部显示出来
cout << "There are " << sum << "algorithms" << endl;
system("pause");
return 0;
}
C++:将一元人民币兑换成1、2、5分的硬币,求换法
最新推荐文章于 2024-01-04 04:00:00 发布