用死亡数除以确诊数并乘 100,按 .3f 输出百分率。
OJ: noi_openjudge
题目 ID: ch0103-06
难度:入门
标签:浮点数数学python
日期: 2026-07-30 23:01
题意
给出确诊数和死亡数,输出死亡率百分数,保留 3 位小数。
思路
死亡率为 / 会得到浮点数,再用 .3f 固定三位小数;百分号是普通字符,直接写在 f-string 末尾。
代码
Python代码
python
confirmed, deaths = map(int, input().split())
print(f"{deaths * 100 / confirmed:.3f}%")C++代码
cpp
#include <cstdio>
int main(){
int a,b,c;
scanf("%d%d",&a,&b);
printf("%0.3lf%%",b*100.0/a);
return 0;
}复杂度
时间复杂度和额外空间复杂度均为
总结
比例题先确认分子和分母的含义,再决定是否需要乘