gpt4 book ai didi

c - 仅使用 50 年代和 20 年代钞票的 ATM 取款 C

转载 作者:太空宇宙 更新时间:2023-11-04 05:48:13 24 4
gpt4 key购买 nike

如何仅使用 20 和 50 的钞票从 ATM 取款?例如,如果我想提取 130 欧元,机器应该给我 1 张 50 的钞票和 4 张 20 的钞票。

要让它正常工作真的很难。有人可以帮助我吗?

我只能做这么多:

#include <stdio.h>

int main() {
int balance = 500;
int withdraw;
int bill_20, bill_50;

printf("How much you want to withdraw?");
scanf("%d", &withdraw);

if ((withdraw >= 20) && (withdraw <= balance) && (withdraw % 10 == 0)
&& (withdraw != 30)) {

if (withdraw >= 50) {
bill_50 = withdraw / 50;
withdraw = withdraw % 50;
printf("You get %d bills of 50s\n", bill_50);
}
if ((withdraw >= 20) && (withdraw < 50)) {
bill_20 = withdraw / 20;
withdraw = withdraw % 20;
printf("You get %d bills of 20s\n", bill_20);
}

} else
printf("Wrong sum");

return 0;
}

最佳答案

好吧,一步一步来:

  1. 取最大数量的 50 个。
  2. 如果剩下的不能在 20 秒内拿走,而我们至少拿了一个 50,放回一个 50。
  3. 休息时尽可能多地抽出 20 秒。
  4. 如果还剩下什么,那就绝望吧。
int bill_50 = withdraw / 50 - (withdraw > 50 && withdraw % 50 % 20);
int bill_20 = (withdraw - bill_50 * 50) / 20;
if (withdraw != bill_50 * 50 + bill_20 * 20)
printf("Cannot put it together.\n");

关于c - 仅使用 50 年代和 20 年代钞票的 ATM 取款 C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53762019/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com