AcWing 656. 钞票和硬币
原题链接
中等
作者:
Noneday
,
2020-06-03 15:58:40
,
所有人可见
,
阅读 635
扩大100倍,否则会由于double类型的精度略微丢失,float*float =double。
#include <iostream>
using namespace std;
int main()
{
double x;
int a;
double arrN[] = { 10000,5000,2000,1000,500,200 };
double arrM[] = { 100,50,25,10,5,1 };
cin >> x;
x = x*100;
cout << "NOTAS:" << endl;
for (int i = 0; i < 6; ++i)
{
a = x / arrN[i];
printf("%d nota(s) de R$ %.2f\n", a, arrN[i]/100);
x = x - a * arrN[i];
}
cout << "MOEDAS:" << endl;
for (int i = 0; i < 6; ++i)
{
a = x / arrM[i];
printf("%d moeda(s) de R$ %.2f\n", a, arrM[i]/100);
x = x - a * arrM[i];
}
}