当前位置:网站首页>PTA 换硬币
PTA 换硬币
2022-08-09 10:58:00 【拾荒大妈】
将一笔零钱换成5分、2分和1分的硬币,要求每种硬币至少有一枚,有几种不同的换法?
输入格式:
输入在一行中给出待换的零钱数额x∈(8,100)。
输出格式:
要求按5分、2分和1分硬币的数量依次从大到小的顺序,输出各种换法。每行输出一种换法,格式为:“fen5:5分硬币数量, fen2:2分硬币数量, fen1:1分硬币数量, total:硬币总数量”。最后一行输出“count = 换法个数”。
输入样例:
13
输出样例:
fen5:2, fen2:1, fen1:1, total:4
fen5:1, fen2:3, fen1:2, total:6
fen5:1, fen2:2, fen1:4, total:7
fen5:1, fen2:1, fen1:6, total:8
count = 4
思路:
因题目要求按5分、2分和1分硬币的数量依次从大到小的顺序,所以fen5=fen5-i,其中i从0增加到x/5,但不等于x/5;同理,fen2=(x-fen55)/2-j;j从0增加到(x-fen55)/2,但不等于(x-fen55)/2。
因题目要求每种硬币至少有一枚,所以要进行(x-5fen5)!=0和(x-5fen5-2fen2)!=0的判断。
#include<stdio.h>
int main()
{
int x;
scanf("%d",&x);
int fen5,fen2,fen1,count=0,total;
for(int i=0;i<x/5;i++)
{
fen5=x/5-i;
if((x-5*fen5)!=0)
{
for(int j=0;j<(x-fen5*5)/2;j++)
{
fen2=(x-fen5*5)/2-j;
if((x-5*fen5-2*fen2)!=0)
{
fen1=(x-5*fen5-2*fen2);
total=fen5+fen2+fen1;
printf("fen5:%d, fen2:%d, fen1:%d, total:%d\n",fen5,fen2,fen1,total);
count++;
}
}
}
}
printf("count = %d",count);
}
边栏推荐
- b站up主:空狐公子 --矩阵求导(分母布局)课程笔记
- Preparation for gold three silver four: how to successfully get an Ali offer (experience + interview questions + how to prepare)
- bit、byte、KB、M、G、T相互关系
- Multi-merchant mall system function disassembly 26 lectures - platform-side distribution settings
- 日期工具类
- MATLAB代码实现三次样条插值
- 【Subpixel Dense Refinement Network for Skeletonization】CVPR2020论文解读
- 类与对象 (下)
- MySQL外键在数据库中的作用
- C语言统计不同单词数
猜你喜欢
Shell script combat (2nd edition) / People's Posts and Telecommunications Press Script 1 Find programs in the PATH
研发需求的验收标准应该怎么写? | 敏捷实践
golang 三种指针类型具体类型的指针、unsafe.Pointer、uintptr作用
激光条纹中心提取——Steger
激光条纹中心提取——灰度重心法
b站up主:空狐公子 --矩阵求导(分母布局)课程笔记
PoseNet: A Convolutional Network for Real-Time 6-DOF Camera Relocalization论文阅读
electron 应用开发优秀实践
【Subpixel Dense Refinement Network for Skeletonization】CVPR2020论文解读
People | How did I grow quickly from programmer to architect?
随机推荐
1003 Emergency (25分)
程序员的专属浪漫——用3D Engine 5分钟实现烟花绽放效果
获取指定年度所有周的工具类
faster-rcnn学习
tensorflow和numpy对应的版本,报FutureWarning: Passing (type, 1) or ‘1type‘ as a synonym of type is deprecate
Cluster understanding
numpy库中的函数 bincount() where() diag() all()
faster-rcnn learn
剖析STM32F103时钟系统
MySQL查询性能优化七种武器之索引潜水
Error: Cannot find module ‘./application‘
vite的原理,手写vite
在线编译matlab,亲测好用
torch.cat()函数的官方解释,详解以及例子
Missing URI template variable ‘employeeNumber‘ for method parameter of type String
二叉树 前序是根在前(根左右)中序(左根右)
Multi-merchant mall system function disassembly 26 lectures - platform-side distribution settings
Jmeter BeanShell post processor
golang源代码阅读,sync系列-Cond
For versions corresponding to tensorflow and numpy, report FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecate