当前位置:网站首页>结果填空 啤酒和饮料
结果填空 啤酒和饮料
2022-07-28 05:19:00 【小白鼠零号】
啤酒每罐2.3元,饮料每罐1.9元。小明买了若干啤酒和饮料,一共花了82.3元。
我们还知道他买的啤酒比饮料的数量少,请你计算他买了几罐啤酒。
注意:答案是一个整数。
答案
11
解题过程
很常规的题目,需要注意这里浮点数比较采用的是:abs(实际值-比较的值)<1e-n 。
附上代码
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
double p_price,y_price;
int x,y;
for(x=0;x<=38;x++)
{
for(y=0;y<=44;y++)
{
if(x<y)
{
p_price=x*2.3;
y_price=y*1.9;
if(abs(p_price+y_price-82.3)<1e-8)
cout<<x<<endl;
}
}
}
return 0;
}
边栏推荐
- When using deep learning training image, the image is too large for segmentation training prediction
- 对极大似然估计、梯度下降、线性回归、逻辑回归的理解
- 冶金物理化学复习 --- 金属的电沉积,还原过程
- 标准C语言学习总结3
- Mutual conversion between latex and word
- [MySQL] solve the problem of MySQL time zone and 8-hour difference in database time
- Advanced multithreading: the role and implementation principle of volatile
- Openjudge: count the number of numeric characters
- 排序之插入排序
- Custom JSON return data
猜你喜欢
随机推荐
JVM notes 3: class loading and bytecode Technology
ArrayList multithreading security solution
C语言回顾(指针篇)
DOM窗口相关数据、操作 & BOM操作
Centos7 install MySQL 5.7
uni-app-双击事件模拟
Interface idempotency problem
Docker deploy mysql5.7.35
函数基础知识以及特殊点
标准C语言总结4
Canvas绘图2
Mabtis (I) basic use of framework
ArcGIS Engine开发资源
Invalid bound statement (not found): com.exam.mapper.UserMapper.findbyid
对象内多个数组的对应下标相加
C语言回顾(字节对齐篇)
DOM--事件链、事件冒泡和捕获、事件代理
The essence of dynamic convolution
C语言回顾(可变参数篇)
树莓派串口









