这个要慢慢理解……
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
using namespace std;
int main()
{
int n,i,j,k,a1,a5,a10;
bool flag;
while(cin>>n>>a1>>a5>>a10&&(n+a1+a5+a10))
{
i=j=k=0;
if(n%5>a1)
{
cout<<"Hat cannot buy tea."<<endl;
continue;
}
i=n%5;
n-=i;
a1-=i;
if(n<=a1)
{
i+=n;
printf("%d YiJiao, %d WuJiao, and %d ShiJiao
",i,j,k);
continue;
}
a1/=5;
n-=5*a1;
i+=5*a1;
if(n<=5*a5)
{
j+=n/5;
printf("%d YiJiao, %d WuJiao, and %d ShiJiao
",i,j,k);
continue;
}
n-=5*a5;
j=a5;
if(n%10==0)
{
if(n<=10*a10)
{
k=n/10;
printf("%d YiJiao, %d WuJiao, and %d ShiJiao
",i,j,k);
continue;
}
else
{
cout<<"Hat cannot buy tea."<<endl;
continue;
}
}
else
{
if(j>0)
j--;
else
{
if(i>=5)
i-=5;
else
{
cout<<"Hat cannot buy tea."<<endl;
continue;
}
}
n+=5;
if(n<=10*a10)
{
k=n/10;
printf("%d YiJiao, %d WuJiao, and %d ShiJiao
",i,j,k);
continue;
}
else
{
cout<<"Hat cannot buy tea."<<endl;
continue;
}
}
}
return 0;
}