酷代码 AI
菜单

给定一个金额(以元为单位,如 345 345),现在想知道支付该金额的各种面额的人民币数量,显示 100 100 元, 50 50 元, 20 20 元, 10 10 元, 5 5 元, 1 1 元各多少张,要求尽量使用大面额的钞票。 输入格式 一个小于 1000 1000 的正整数。 输出格式 输出分行,每行显示一个整数,从上到下分别表示 100 100 元, 50 50 元, 20 20元, 10 10 元, 5 5 元, 1 1 元人民币的张数。

以下是使用 Python 实现该功能的代码: ```python # 获取用户输入的金额 amount = int(input()) # 计算各面额人民币的张数 hundred_count = amount // 100 amount %= 100 fifty_count = amount // 50 amount %= 50 twenty_count = amount // 20 amount %= 20 ten_count = amount // 10 amount %= 10 five_count = amount // 5 amount %= 5 one_count = amount # 输出各面额人民币的张数 print(hundred_count) print(fifty_count) print(twenty_count) print(ten_count) print(five_count) print(one_count) ``` 以下是使用 Java 实现该功能的代码: ```java import java.util.Scanner; public class Main { public static void main(String[] args) { // 创建 Scanner 对象用于读取用户输入 Scanner scanner = new Scanner(System.in); // 读取用户输入的金额 int amount = scanner.nextInt(); // 计算各面额人民币的张数 int hundredCount = amount / 100; amount %= 100; int fiftyCount = amount / 50; amount %= 50; int twentyCount = amount / 20; amount %= 20; int tenCount = amount / 10; amount %= 10; int fiveCount = amount / 5; amount %= 5; int oneCount = amount; // 输出各面额人民币的张数 System.out.println(hundredCount); System.out.println(fiftyCount); System.out.println(twentyCount); System.out.println(tenCount); System.out.println(fiveCount); System.out.println(oneCount); // 关闭 Scanner 对象 scanner.close(); } } ``` 以下是使用 C++ 实现该功能的代码: ```cpp #include <iostream> using namespace std; int main() { // 定义变量用于存储输入的金额 int amount; // 获取用户输入的金额 cin >> amount; // 计算各面额人民币的张数 int hundredCount = amount / 100; amount %= 100; int fiftyCount = amount / 50; amount %= 50; int twentyCount = amount / 20; amount %= 20; int tenCount = amount / 10; amount %= 10; int fiveCount = amount / 5; amount %= 5; int oneCount = amount; // 输出各面额人民币的张数 cout << hundredCount << endl; cout << fiftyCount << endl; cout << twentyCount << endl; cout << tenCount << endl; cout << fiveCount << endl; cout << oneCount << endl; return 0; } ``` 代码解释: 1. 输入获取:首先获取用户输入的金额。 2. 计算各面额张数:从大面额开始,依次计算每种面额的张数,并更新剩余金额。 3. 输出结果:按顺序输出各面额人民币的张数。 [2026-01-29 17:10:17 | AI问答 | 784点数解答]

服务商
相关提问
发财导航,免费问AI
实用工具查看更多