单点时限: 2.0 sec
内存限制: 256 MB
李奶奶年纪大了算术不太好了,每次买东西想不清要怎么付钱,请你写一个程序帮助李奶奶。对于每一个金额(以元为单位的整数,如 412 元), 显示支付这个金额的各种面额人民币的数量,要求从最大面额的人民币给起,直到最小面额的人民币,即 100 元、50 元、20 元、10 元、5 元、1 元各多少数量。
输入格式
第 1 行:整数 T (1≤T≤10) 为问题数
第 2 ∽ T+1 行:每一个问题中的金额 n (0⩽n⩽10000)。
输出格式
对于每个问题,输出一行问题的编号(0 开始编号,格式:case #0:
等),然后在一行中输出 100 元、50 元、20 元、10 元、5 元、1 元各多少数量,用空格分隔,最后一个数没有空格。
样例
input
4 0 68 78 10
output
case #0: 0 0 0 0 0 0 case #1: 0 1 0 1 1 3 case #2: 0 1 1 0 1 3 case #3: 0 0 0 1 0 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
int jobs, temp;
vector<int> moneys;
// 输入
cin >> jobs;
for(int i=0;i<jobs;i++){
cin >> temp;
moneys.insert(moneys.end(), temp);
}
// 格式化与输出
int money, nums[6];
int values[6] = {100,50,20,10,5,1};
for(int i=0;i<jobs;i++){
money = moneys[i];
if(money == 0){
cout <<"case #"<<i<<":\n"<<"0 0 0 0 0 0"<<endl;
}
while(money > 0)
{
cout <<"case #"<<i<<":" <<endl;
for(int j=0;j<6;j++){
nums[j] = money/values[j];
money = money % values[j];
printf("%d", nums[j]);
if(j==5) break;
printf(" ");
}
if(i == jobs-1) break;
cout << endl;
}
}
return 0;
}