AcWing 656. 钞票和硬币
原题链接
中等
作者:
Asiim0v
,
2020-02-24 17:11:17
,
所有人可见
,
阅读 2190
C++ 代码
#include <iostream>
using namespace std;
int main()
{
double N;
cin >> N;
int n = (int)N;
int N_sub = 100*N - 100*n;
cout << "NOTAS:" <<endl;
cout << n/100 << " nota(s) de R$ 100.00" <<endl;
n %= 100;
cout << n/50 << " nota(s) de R$ 50.00" <<endl;
n %= 50;
cout << n/20 << " nota(s) de R$ 20.00" <<endl;
n %= 20;
cout << n/10 << " nota(s) de R$ 10.00" <<endl;
n %= 10;
cout << n/5 << " nota(s) de R$ 5.00" <<endl;
n %= 5;
cout << n/2 << " nota(s) de R$ 2.00" <<endl;
n %= 2;
cout << "MOEDAS:" <<endl;
cout << n << " moeda(s) de R$ 1.00" <<endl;
cout << N_sub/50 << " moeda(s) de R$ 0.50" <<endl;
N_sub %= 50;
cout << N_sub/25 << " moeda(s) de R$ 0.25" <<endl;
N_sub %= 25;
cout << N_sub/10 << " moeda(s) de R$ 0.10" <<endl;
N_sub %= 10;
cout << N_sub/5 << " moeda(s) de R$ 0.05" <<endl;
N_sub %= 5;
cout << N_sub << " moeda(s) de R$ 0.01" <<endl;
return 0;
}
100*(N - n)为啥就不对了,N_sub直接变成零了
菜鸡问的问题有点菜哈
int N_sub = 100N - 100n;
这个什么意思啊?
N是double类型,n是对其做 int 类型强制转换,C++中 int 强制转换会舍弃小数位,
所以 N_sub 的结果就可以把小数点后面两位提取出来
okok.三克油