刚看到的美国一个论坛上的C++题目 有没有人能做出来

sunsold 2009-03-14 05:36:18
我仔细看了 做了个程序 感觉不是很正确 不知道还有高手能给出解答吧

Suppose you can buy a chocolate bar from the vending machine
for $1 each. Inside every chocolate bar is a coupon. You can redeem seven
coupons for one chocolate bar from the machine. You would like to know how
many chocolate bars you can eat, including those redeemed via coupon, if you
have n dollars.
For example, if you have 20 dollars then you can initially buy 20 chocolate bars.
This gives you 20 coupons. You can redeem 14 coupons for two additional
chocolate bars. These two additional chocolate bars give you two more coupons,
so you now have a total of eight coupons. This gives you enough to redeem
for one final chocolate bar. As a result you now have 23 chocolate bars
and two leftover coupons.
Write a program that inputs the number of dollars and outputs how many chocolate
bars you can collect after spending all your money and redeeming as many
coupons as possible. Also output the number of leftover coupons. The easiest
way to solve this program is to use a loop.
...全文
291 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
arong1234 2009-03-15
  • 打赏
  • 举报
回复
对不起这是我看错了,我把“有没有人”看成“没有人”了
[Quote=引用 17 楼 sunsold 的回复:]
是美国论坛的题好吧 楼主说没有人做的出了吗!? 你说的都以为我在忽悠大家
[/Quote]
sunsold 2009-03-15
  • 打赏
  • 举报
回复
是美国论坛的题好吧 楼主说没有人做的出了吗!? 你说的都以为我在忽悠大家
arong1234 2009-03-15
  • 打赏
  • 举报
回复
而且这么简单的题目用得着到“美国”的论坛上取找啊:)
arong1234 2009-03-15
  • 打赏
  • 举报
回复
题目太简单,楼主还是应该自己做做

[Quote=引用 13 楼 sunsold 的回复:]
这确实是美国论坛上的题啊 这个还能有假..............
[/Quote]
sunsold 2009-03-15
  • 打赏
  • 举报
回复
Thanks for everyone giving the answers
sunsold 2009-03-15
  • 打赏
  • 举报
回复
这确实是美国论坛上的题啊 这个还能有假..............
blueness21 2009-03-14
  • 打赏
  • 举报
回复
E文不错,哈哈哈
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 arong1234 的回复:]
其实:
不说美国人你不回答,所以LZ说美国论坛上的,其实只是LZ老师布置作业:这就是标题党
这个题目显然不难,为什么说没有人做得出?其实没有人只是等于楼主做不出而已
现在人真是越来越不实在了
引用 4 楼 hairetz 的回复:
美国人这么傻?这样的题目做不出来?

C/C++ code
int total=0;
int coupon_left=0;
f(int money)
{
money+=coupon_left/7; //每次兑换考虑coupon_…
[/Quote]

。。原来被玩了,不过楼主还得翻译成英文,也够累的,不会老师直接布置个英文的作业吧。。
aaaa3105563 2009-03-14
  • 打赏
  • 举报
回复
看不懂
fairchild811 2009-03-14
  • 打赏
  • 举报
回复
算了楼主想这么长个英文题目也不简单了

如果老美真是做不出来,那就不知道老美,那估计我们现在还没有电脑用
arong1234 2009-03-14
  • 打赏
  • 举报
回复
其实:
不说美国人你不回答,所以LZ说美国论坛上的,其实只是LZ老师布置作业:这就是标题党
这个题目显然不难,为什么说没有人做得出?其实没有人只是等于楼主做不出而已
现在人真是越来越不实在了
[Quote=引用 4 楼 hairetz 的回复:]
美国人这么傻?这样的题目做不出来?

C/C++ code
int total=0;
int coupon_left=0;
f(int money)
{
money+=coupon_left/7; //每次兑换考虑coupon_left
coupon_left=coupon_left%7; // coupon_left永远<7
total+=money; //moneyd兑换巧克力
coupon_left+=money%7; //同时…
[/Quote]
grellen 2009-03-14
  • 打赏
  • 举报
回复
#include<iostream>
using namespace std;
int main()
{
int money, coupon,chocolate;
cout <<"Input your money " <<endl;
cin>>money;
chocolate = coupon = money;
while ( coupon >= 7 )
{
chocolate += coupon / 7;
coupon = coupon % 7 + coupon / 7;
}
cout<<"You can buy " <<chocolate <<" chocolate and left "<<coupon<<" coupon"<<endl;
}
  • 打赏
  • 举报
回复
coupon_left是最后剩下的优惠券
Laozql 2009-03-14
  • 打赏
  • 举报
回复
我的代码:

#include<iostream>

using namespace std;

int main(void)
{
int dollars,present_coupons,chocolate;
cout<<"Please Input The Dollars:"<<endl;
cin>>dollars;
chocolate=dollars;
present_coupons=dollars;
do{
chocolate +=present_coupons/7;
present_coupons=present_coupons%7+present_coupons/7;;
}while(present_coupons>=7);
cout<<"You Can Get "<<chocolate<<" chocolates."<<endl;
cout<<"You Have "<<present_coupons<<" coupons left."<<endl;
return 0;
}

多多指教!
  • 打赏
  • 举报
回复
美国人这么傻?这样的题目做不出来?

int total=0;
int coupon_left=0;
f(int money)
{
money+=coupon_left/7; //每次兑换考虑coupon_left
coupon_left=coupon_left%7; // coupon_left永远<7
total+=money; //moneyd兑换巧克力
coupon_left+=money%7; //同时有优惠券
if(money!=0) //没钱而coupon_left<7,没得玩了
f(money/7);
}

void main()
{
int money;
cout <<"Input your money " <<endl;
cin>>money;
f(money);
cout<<"You can buy " <<total <<" chocolate"<<endl;
}


wbgeorge 2009-03-14
  • 打赏
  • 举报
回复
LZ这个也不是很难吧,只要注意手头只有6个coupon时也能换一个巧克力就行啦
chin_chen 2009-03-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 hmzgz81 的回复:]
E文太差,需求看不太明白,帮顶
[/Quote]]
替你google了一下:题目大意


假设你可以买巧克力从自动售货机
为每个售价一元。在每一个巧克力棒是一种优惠券。您可以兑换7
优惠券从一个巧克力棒的机器。您想知道如何
许多巧克力可以吃,包括那些通过优惠券兑换,如果你
有ñ美元。
例如,如果您有20美元,那么你就可以开始购买20巧克力棒。
这使您20券。您可以兑换14券两项附加
巧克力棒。这两个额外的巧克力棒给你两个更优惠券,
所以你现在有一个共有8个券。这使您足够赎回
最后一次巧克力棒。由于你现在有23个巧克力棒
和两个剩余券。
写程序,投入美元的人数和产出多少巧克力
酒吧,您可以收集后,所有的钱和挽救许多
优惠券可能。还输出人数剩券。最简单的
方式来解决这个程序是使用一个循环。
hmzgz81 2009-03-14
  • 打赏
  • 举报
回复
E文太差,需求看不太明白,帮顶

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧