ACM题。一直wrong answer...need your help.

LHanL93 2012-03-13 07:34:24
Vending Machine

--------------------------------------------------------------------------------

Time limit: 1000MS Memory limit: 32768K
Total Submit: 10 Accepted: 0


--------------------------------------------------------------------------------

The items sold by a vending machine sell for a whole number of dollars. The vending machine returns change in the form of one-dollar coins, five-dollar bills, and ten-dollar bills. For any particular purchase, the number of one-dollar coins returned is less than 5; and the number of five-dollar bills is less than 2.

Input
The input consists of a number of test cases. For each test case, there will be one line of input, containing two integers: the purchase price of an item and the amount entered into the vending machine by the customer. The two integers are separated by one blank space. The input is terminated by a line containing two zeros, this line will not be processed.

Output
For each test case, thre will be one line of output, consisting of: the case number, the amount of the change, and the number of ten- and five-dollar bills and one-dollar coins returned by the vending machine for the particular purchase. The format is illustrated by the sample output. In places where the output shows a blank space, exactly one blank space is required.

Sample Input
72 100
37 200
5 50
0 0

Sample Output
Case 1: 28 = 2 * 10 + 1 * 5 + 3 * 1
Case 2: 163 = 16 * 10 + 0 * 5 + 3 * 1
Case 3: 45 = 4 * 10 + 1 * 5 + 0 * 1

//下面是我的代码。
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
__int64 all,count,pay,give,i,time;
time=1;
while(scanf("%I64d%I64d",&all,&pay)!=EOF)
{
if(all==0&&pay==0)
break;
count=0;
give=pay-all;
for(i=0;;i++)
{
if(give-10*i==0)
break;
if(give-10*i<0)
{
i--;
break;
}
}
printf("Case %I64d: %I64d = %I64d * 10",time,give,i);
give-=10*i;
if(give>0)
{
for(i=0;;i++)
{
if(give-5*i==0)
break;
if(give-5*i<0)
{
i--;
break;
}
}
cout<<" + ";
printf("%I64d",i);
cout<<" * 5";
give-=5*i;
if(give>0)
{
for(i=0;;i++)
if(give-i==0)
break;
cout<<" + ";
printf("%I64d",i);
cout<<" * 1"<<endl;
time++;
continue;
}
else
{
cout<<" + "<<"0"<<" * 1"<<endl;
time++;
}
}
else
{
cout<<" + "<<"0"<<" * 5";
cout<<" + "<<"0"<<" * 1"<<endl;
time++;
}
}
return 0;
}
...全文
137 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

65,189

社区成员

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

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