AcWing 656. 钞票和硬币
1. 地址
https://www.acwing.com/problem/content/658/
2. 解答
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
int money[6] = {100,50,20,10,5,2};
double coins[6] = {1.0,0.50,0.25,0.10,0.05,0.01};
double luxury;
scanf("%lf",&luxury);
// 这题由于具有小数,所以当做除法和模除时,就会有问题
// 因此,我们需要把小数转换为整数 把元->分
int cents = luxury * 100;
printf("NOTAS:\n");
for(int i=0;i<6;i++){
//转换
printf("%d nota(s) de R$ %d.00\n",cents / (money[i] * 100),money[i]);
// 这里也要进行相应的转换
cents = cents % (money[i] * 100);
}
printf("MOEDAS:\n");
for(int i=0;i<6;i++){
printf("%d moeda(s) de R$ %.2f\n",cents / int(coins[i] * 100),coins[i]);
// 这里也要进行相应的转换
cents = cents % int(coins[i] * 100);
}
return 0;
}
标签:钞票,硬币,int,656,luxury,AcWing
From: https://www.cnblogs.com/gao79135/p/17366236.html