首页 > 其他分享 >Batting Average

Batting Average

时间:2022-11-19 07:55:24浏览次数:39  
标签:digits dfrac Average Sample leq Input decimal Batting

Problem Statement

Takahashi is making a computer baseball game.
He will write a program that shows a batter's batting average with a specified number of digits.

There are integers $A$ and $B$, which satisfy $1 \leq A \leq 10$ and $0 \leq B \leq A$.
Let $S$ be the string obtained as follows.

  • Round off $\dfrac{B}{A}$ to three decimal digits, then write the integer part ($1$ digit), . (the decimal point), and the decimal part ($3$ digits) in this order, with trailing zeros.

For example, if $A=7$ and $B=4$, then $\dfrac{B}{A} = \dfrac{4}{7} = 0.571428\dots$ rounded off to three decimal digits is $0.571$. Thus, $S$ is 0.571.

You are given $A$ and $B$ as the input and asked to print $S$.

Constraints

  • $1 \leq A \leq 10$
  • $0 \leq B \leq A$
  • $A$ and $B$ are integers.

Input

The input is given from Standard Input in the following format:

$A$ $B$

Output

Print $S$ in the format specified in the Problem Statement. Note that answers in different formats will be considered wrong.


Sample Input 1

7 4

Sample Output 1

0.571

As explained in the Problem Statement, $\dfrac{B}{A} = \dfrac{4}{7} = 0.571428\dots$ rounded off to three decimal digits is $0.571$. Thus, $S$ is 0.571.


Sample Input 2

7 3

Sample Output 2

0.429

$\dfrac{B}{A} = \dfrac{3}{7} = 0.428571\dots$ rounded off to three decimal digits is $0.429$. (Note that it got rounded up.)
Thus, $S$ is 0.429.


Sample Input 3

2 1

Sample Output 3

0.500

$\dfrac{B}{A} = \dfrac{1}{2} = 0.5$ rounded off to three decimal digits is again $0.5$.
Thus, $S$ is 0.500. Note that it must have three decimal places.


Sample Input 4

10 10

Sample Output 4

1.000

Sample Input 5

1 0

Sample Output 5

0.000

直接按题意模拟,输出 \(\frac{a}{b}\),保留三位即可。

#include<cstdio>
int a,b;
int main()
{
	scanf("%d%d",&a,&b);
	printf("%.3lf",1.00*b/a);
}

标签:digits,dfrac,Average,Sample,leq,Input,decimal,Batting
From: https://www.cnblogs.com/mekoszc/p/16905397.html

相关文章

  • HDU2376 Average distance
    题目链接:传送门求树上任意两点间的路径和的平均值非常套路统计每条边被经过多少次就是两边的点数的乘积注意精度就好#include<cstdio>#include<cstring>#include<alg......
  • HDU2376——Average distance(思维+树形DP)
    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2376原文:https://www.codenong.com/cs109682980/题意:给定一棵树,有边权,求树上任意两点之间距离的和的平均值。思路......
  • AT2294 [AGC009E] Eternal Average
    题目传送门考虑求值的过程,容易发现我们会形成一颗\(k\)叉树,然后最后的总和是每个\(1\)点对应的深度的\(\frac{1}{k}\)次幂和。容易发现在同一层有\(k\)个同样的点可以用......