硬币 [英] Coins

查看:101
本文介绍了硬币的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有一项我不理解并需要帮助的作业。


编写一个程序,读取命令行整数N(便士数)并打印使用美国硬币(季度,硬币,镍币和硬币)进行更改的最佳方式(最少数量的硬币)。你的算法应该分配尽可能多的四分之一,然后是硬币,然后是镍币,最后是硬币。

Hi i have an assignment that i don''t understand and need help in.

Write a program that reads in a command line integer N(number of pennies) and prints out the best way(fewest number of coins) to make change using US coins (quarters, dimes, nickels and pennies only). Your algorithm should dispense as many quarters as possible, then dimes, then nickels, and finally pennies.

推荐答案


你好我有一个我不理解并需要帮助的作业。


编写一个程序,读取命令行整数N(便士数)并打印出最佳方式(使用美国硬币进行更改的最少数量的硬币)(仅限季度,硬币,镍币和硬币)。你的算法应该尽可能多地分配,然后是硬币,然后是镍币,最后是硬币。
Hi i have an assignment that i don''t understand and need help in.

Write a program that reads in a command line integer N(number of pennies) and prints out the best way(fewest number of coins) to make change using US coins (quarters, dimes, nickels and pennies only). Your algorithm should dispense as many quarters as possible, then dimes, then nickels, and finally pennies.



这里有一点提示:假设你有81便士;看这个:


81/25 == 3(季度)

81%25 == 6(其余的变化)


等等。


亲切的问候,


Jos

Here''s a little hint: suppose you''ve got 81 pennies; watch this:

81/25 == 3 (quarters)
81%25 == 6 (rest of the change)

etc. etc.

kind regards,

Jos


为什么你做了81%25我怎么能得到其余的
why did you do 81%25 and how can i get the rest



为什么你做81%25我怎么能得到其余的
why did you do 81%25 and how can i get the rest



%is运算符是Java'(以及C和C ++的)模运算符。 81%25 == 6

因为当你将81除以25时其余的是6。


亲切的问候,


Jos

The % is operator is Java''s (and C and C++''s) modulo operator. 81%25 == 6
because the rest is 6 when you divide 81 by 25.

kind regards,

Jos


这篇关于硬币的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆