Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

郁闷

Posted by xingkongnqb at 2008-05-24 02:23:47 on Problem 2818
#include<iostream>
using namespace std;
int main()
{
	int b[4],t,s,q,d,n,p,c;
    cin>>q>>d>>n>>p>>c;
	while(q!=0||d!=0||n!=0||p!=0||c!=0)
	{if((25*q+10*d+5*n+p)<c||c%5>p||c%10>(5*n+p)||c%25>(10*d+5*n+p))cout<<"Cannot dispense the desired amount."<<endl;
	else 
	{t=c/5;s=c%5;
	if(t/5<=q)b[0]=t/5;
	else b[0]=q;
	t=t-b[0]*5;
	if(t/2<=d)b[1]=t/2;
	else b[1]=d;
	t=t-b[1]*2;
	if(t<=n)b[2]=t;
	else b[2]=n;
	t=t-b[2];
	b[3]=5*t+s;
	if(c%10==0&&c/10>=d){int a[4];a[0]=a[2]=a[3]=0;a[1]=c/10;int x=a[1];
	int y=b[0]+b[1]+b[2]+b[3];
	if(x<=y)
	{cout<<"Dispense "<<a[0]<<" quarters, "<<a[1]<<" dimes, "<<a[2]<<" nickels, and "<<a[3]<<" pennies."<<endl;goto L;}}
	cout<<"Dispense "<<b[0]<<" quarters, "<<b[1]<<" dimes, "<<b[2]<<" nickels, and "<<b[3]<<" pennies."<<endl;}
L:	cin>>q>>d>>n>>p>>c;
	}
return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator