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

LHanL93 LHanL93 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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;
}
...全文

相关推荐

评论
收藏 已收藏
分享
返回顶部
LHanL93
C++ 语言 65,214 成员 250,514 内容