
多个测试用例
#include <iostream>
using namespace std;
int main()
{
int n; // 老师数
int sum = 0; // 总计钞票的数量
int m;
int x; // 每个老师的钱
int a[6] = {100, 50, 10, 5, 2, 1}; //存放币值
while(true)
{
cin >> n;
if(n == 0)
break;
for(int i=0; i<n; i++)
{
cin >> x;
for(int i=0; i<6; i++)
{
m = x / a[i];
x -= a[i]*m;
sum += m;
}
}
cout << sum << endl;
sum = 0;
}
return 0;
}
本文介绍了一个使用C++编写的货币兑换程序,该程序能够处理多个测试用例,通过输入老师的数量和每位老师持有的货币数量,计算并输出总共有多少张不同面额的纸币。程序使用了数组来存储币值,并通过循环实现了货币的兑换过程。
5万+

被折叠的 条评论
为什么被折叠?



