硬币问题

#include<iostream>
#include<math.h> 
using namespace std;

int main() 
{
	const int V[6] = {1,5,10,50,100,500};
	int A;
	int C[6];
	cout<<"请输入各种面值硬币的数目:" <<endl;
	for(int j=0;j<6;j++)
	{ 
		cout<<"C"<<j<<"="; 
		cin>>C[j];
	}
	cout<<"A=";
	cin>>A; 
	int ans=0;
	for(int i=5; i>=0; i--) {
		int t=min(A/V[i],C[i]);  //使用硬币i的数目 
		A -=t*V[i];
		ans +=t;   //总的硬币数目 
		cout<<V[i]<<"元硬币的数目为:"<<t<<endl; 
	}
//	cout<<i<<"元硬币数目为:"<<t<<endl; 
	printf("%d\n",ans);
}

  

posted @ 2019-09-19 19:39  Maggieisxin  阅读(111)  评论(0编辑  收藏  举报