当前位置:网站首页>结果填空 啤酒和饮料
结果填空 啤酒和饮料
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;
}
边栏推荐
猜你喜欢

Custom JSON return data

环形链表问题

How Visio can quickly generate the same pattern and image matrix

CAD-GIS数据转换

在线词云图生成(以WordArt为例)

Arcgis Engine安装的若干问题
![[idea plug-in artifact] teaches you how to set all attributes in an entity class with one click of idea](/img/d6/4e69480c5ad5040ee48941ca0fcb37.png)
[idea plug-in artifact] teaches you how to set all attributes in an entity class with one click of idea

wangeditor(@4.7.15)-轻量级的富文本编辑器

media-搭建直播服务器

Mutual conversion between latex and word
随机推荐
排序之插入排序
Openjudge: judge whether the string is palindrome
The way of deep learning thermodynamic diagram visualization
Review of Metallurgical Physical Chemistry - gas liquid phase reaction kinetics
Microsoft Edge浏览器插件(1)
ArcMap中的距离工具条(Distance)
Leetcode 随即链表的深拷贝
Oracle create table, delete table, modify table (add field, modify field, delete field) statement summary
C语言回顾(指针篇)
设置滚动条
Thesis writing function words
C语言走迷宫
顺序表oj之合并两个有序数组
Use of IO streams
ArcGIS地图制作的注记、格网添加
标准C语言总结1
Custom JSON return data
Invalid bound statement (not found): com.exam.mapper.UserMapper.findbyid
You must configure either the server or JDBC driver (via the ‘serverTimezone)
The Monte Carlo method solves the PI and draws points with turtle, and completes the progress bar problem