ACM题。一直wrong answer...need your help.
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;
}
--------------------------------------------------------------------------------
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;
}
...全文
相关推荐
ACM刷题技巧及一些题目解答
在ACM(国际大学生程序设计竞赛)中,提高编程技能和掌握特定的解题策略是至关重要的。本资料集合提供了一些关键的ACM刷题技巧和一些具体题目的解答,旨在帮助参赛者提升解决问题的能力。
ACM题集-ACM训练题集-超多ACM题集汇总-解题源码
这个压缩包文件“ACM题集_ACM训练题集_超多ACM题集汇总_解题源码”显然是一个集合,包含了大量ACM竞赛相关的题目和已经解决的源代码,对于学习和准备ACM比赛的学员来说是宝贵的资源。
杭电acm题集以及浙大acm题集
《杭电ACM题集与浙大ACM题集》是专为热衷于程序设计和算法提升的朋友精心准备的资源。这两份题集涵盖了大量经典的编程竞赛题目,旨在帮助学习者提高C、C++、Java等编程语言的算法设计与实现能力。
经典ACM题Gone Fishing C++源代码
《经典ACM题“Gone Fishing”的C++源代码解析》ACM竞赛中的题目“Gone Fishing”是一道涉及枚举与贪心算法的经典问题。
ACM在线评测系统 NYOJ 题库 离线看题网页版 nyoj
系统会对每一种可能的输入进行验证,判断程序的输出是否符合预期,从而给出评测结果,如“Accepted”(通过)、"Wrong Answer"(答案错误)或"Time Limit Exceeded"(超时


