题目内容:
将n美分转换成25、10、5和1美分的硬币总共有多少种转换方法?
运行结果如下:
25
13
如果n不在0~99之间,输出提示信息“the money is invalid!”
运行结果如下:
101
the money is invalid!
输入格式:
整数,表示美分数
输入可能不是[0,99]之间的整数。输入不在该区间时,输出为“the money is invalid!”。
输出格式:
转换方法数或者提示信息“the money is invalid!”(不带引号啊,单词间只有一个空格)
输入样例:
25
输出样例:
13
时间限制:2000ms内存限制:64000kb
#include<iostream>
using namespace std;
int main()
{
int n,sum;
sum=0;
cin>>n;
if(n<0||n>99){
cout<<"the money is invalid!"<<endl;
return 0;
}
else{
for(int a=0;a<=n;a++){
for(int b=0;b<=n;b++){
for(int c=0;c<=n;c++){
for(int d=0;d<=n;d++){
if(25*a+10*b+5*c+d==n){
sum = sum+1;
}
}
}
}
}
cout<<sum<<endl;
}
return 0;
}