653. 钞票
在这个问题中,你需要读取一个整数值并将其分解为多张钞票的和,每种面值的钞票可以使用多张,并要求所用的钞票数量尽可能少。
请你输出读取值和钞票清单。
钞票的可能面值有 100,50,20,10,5,2,1。
输入格式
输入一个整数 N。
输出格式
参照输出样例,输出读取数值以及每种面值的钞票的需求数量。
数据范围
0<N<1000000
输入样例:
576
输出样例:
576
5 nota(s) de R$ 100,00
1 nota(s) de R$ 50,00
1 nota(s) de R$ 20,00
0 nota(s) de R$ 10,00
1 nota(s) de R$ 5,00
0 nota(s) de R$ 2,00
1 nota(s) de R$ 1,00
题解
#include<iostream>
using namespace std;
int main()
{
//a:100, b:50, c:20, d:10, e:5, f:2, g:1
int x, temp; //用于暂存
int a, b, c, d, e, f, g, h; //存储每种面值的钞票的需求数量
cin >> x;
temp = x;
int N = x;
/*1. 对输入数值进行取余,得到除100 面额以外的钞票
2. 对输入数值进行除法运算,得到100的钞票数
3. 把temp赋给x,方便下次运算*/
temp = temp % 100; //76
a = x / 100; //5
x = temp; //76
//下面步骤同上
temp = temp % 50; //26
b = x / 50; //1
x = temp; //26
temp = temp % 20;
c = x / 20;
x = temp;
temp = temp % 10;
d = x / 10;
x = temp;
temp = temp % 5;
e = x / 5;
x = temp;
temp = temp % 2;
f = x / 2;
x = temp;
temp = temp % 1;
g = x / 1;
x = temp;
cout << N << endl;
cout << a << " nota(s) de R$ 100,00" << endl;
cout << b << " nota(s) de R$ 50,00" << endl;
cout << c << " nota(s) de R$ 20,00" << endl;
cout << d << " nota(s) de R$ 10,00" << endl;
cout << e << " nota(s) de R$ 5,00" << endl;
cout << f << " nota(s) de R$ 2,00" << endl;
cout << g << " nota(s) de R$ 1,00" << endl;
return 0;
}
题目链接:
https://www.acwing.com/problem/content/description/655/
拜托大家一键三连(。・ω・。)ノ♡