洛谷P5706 【深基2.例8】再分肥宅水(c ,c++混合版)

题目描述
现在有 t 毫升肥宅快乐水,要均分给 n 名同学。每名同学需要 2 个杯子。现在想知道每名同学可以获得多少毫升饮料(严格精确到小数点后 3 位),以及一共需要多少个杯子。输入一个实数 t 和一个整数 n,使用空格隔开。输出两个数字表示答案,使用换行隔开。

0\leq t\leq 100000≤t≤10000且不超过3位小数,1\leq n\leq 10001≤n≤1000

输入格式

输出格式

输入输出样例
输入

500.0 3

输出 #1复制

166.667
6

代码1:(取了C语言的精确位数的巧了)

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	float t;
	int  n;
	cin >> t >> n;
	float a = t / n;
	int b = 2 * n;
	printf("%0.3f\n%d", a, b);//在洛谷测试要加#include<cstdio>
	return 0;
}

代码2:(c++的精确方法)

#include<iostream>
#include<iomanip>
// setprecision(3)需要它
using namespace std;
int main()
{
	float t;
	int  n;
	cin >> t >> n;
	float a = t / n;
	int b = 2 * n;
	//fixed 使得用setprecision(3)精确后仍能按小数显示
	cout << fixed << setprecision(3) << a << endl << b;
	return 0;
}
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值