# 【深基2.例8】再分肥宅水
## 题目描述
现在有 $t$ 毫升肥宅快乐水,要均分给 $n$ 名同学。每名同学需要 $2$ 个杯子。现在想知道每名同学可以获得多少毫升饮料(严格精确到小数点后 $3$ 位),以及一共需要多少个杯子。
## 输入格式
输入一个实数 $t$ 和一个正整数 $n$,使用空格隔开。
## 输出格式
输出两行。
第一行输出一个三位小数,表示可以获得多少毫升饮料。第二行输出一个正整数,表示一共需要多少个杯子。
## 样例 #1
### 样例输入 #1
```
500.0 3
```
### 样例输出 #1
```
166.667
6
```
正确代码先行!!!
C++
#include<iostream>
using namespace std;
int main(){
double t;
int n;
cin>>t>>n;
printf("%.3lf\n%d",t/n,n*2);
return 0;
}
C#
#include<stdio.h>
int main(){
double t;
int n;
scanf("%lf%d",&t,&n);
printf("%.3lf\n%d",t/n,n*2);
return 0;
}
而在C++里我们可用到一个setprecision函数
这时代码会变成!
#include<bits/stdc++.h>
using namespace std;
int main(){
double t;
int n;
cin>>t>>n;
cout<<setprecision(3)<<fixed<<t/n<<endl<<n*2;
return 0;
}
setprecision()函数,用于输出浮点有效字数位,例如题中样例500.0/3应为166.6666……,而我们用一句↓即可保留为想要的三位有效数
cout<<setprecision(3)<<fixed<<a/b<<endl<<b*2;
此函数还可和fixed函数,showpoint一起使用