首页 > 试题广场 >

疫情死亡率

[编程题]疫情死亡率
  • 热度指数:41215 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
\hspace{15pt}某种病毒正在人群中肆虐,你作为龙国最强病毒专家的最强助手,需要帮助他分析目前病毒的死亡率。

\hspace{15pt}给定感染某种病毒的确诊人数 c 与死亡人数 d,请计算该种病毒的死亡率,死亡率定义为 \dfrac{d}{c}\times100\%

输入描述:
\hspace{15pt}输入一行两个整数 c,d \left(1 \leqq c,d \leqq 10^9\right),分别表示某种病毒造成的确诊人数和死亡人数。


输出描述:
\hspace{15pt}输出死亡率,以百分数形式表示,结果保留小数点后三位,并在末尾加上百分号 \%
示例1

输入

10433 280

输出

2.684%
c,d=map(int,input().split())
res=d/c * 100 
print(format(res,'.3f')+'%')

发表于 2025-06-23 20:18:50 回复(0)
a,b=input().split()
c=int(b)/int(a)
print("{:.3%}".format(c))

发表于 2025-06-13 15:41:05 回复(0)
#include <stdio.h>

int main()
 {  
    int c,d;
    scanf("%d %d",&c,&d);
    double a = (double)d/c * 100.0;
    printf("%.3lf%%\n",a);//可以用%%输出%
       return 0;
}
发表于 2025-09-15 12:24:46 回复(0)
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
    int c,d;
    cin >>c;
    cin >>d;
    double a;
    a=(double) d/c*100;
    
    cout<<fixed<<setprecision(3)<<a<<"%";
}

发表于 2025-08-14 11:29:38 回复(0)
#include <stdio.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    float c = 100.0*b/a;//注意100.0而不能用100,这样等号右边计算结果才能是浮点数
    printf("%.3f%\n", c);
    return 0;
}
发表于 2025-06-12 16:45:21 回复(2)
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
      int a=in.nextInt();
      int b=in.nextInt();
      double c;
      c=(b*100.0)/a;
      System.out.printf("%.3f%%",c);
    }
}
发表于 2025-11-10 16:27:40 回复(0)
a,b = map(int,input().split())
n = b / a * 100
print("{:.3f}%".format(n))
发表于 2025-10-30 15:11:40 回复(0)
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        //确诊人数
        int c=sc.nextInt();
        //死亡人数
        int d=sc.nextInt();
        //保留精度百分数形式表示
        double deathRate=(d*100.0)/c;
        System.out.printf("%.3f%%",deathRate);
       
}
}
发表于 2025-10-30 11:10:22 回复(0)
#include <stdio.h>

int main() {
    int c, d;
    scanf("%d %d",&c,&d);
    float e = 100.0*d/c;
    printf("%.3f%%",e);
    return 0;
}
发表于 2025-10-23 16:09:32 回复(0)
#include <stdio.h>

int main() {
    float a, b;
    scanf("%f %f", &a, &b);
    printf("%.3f%%\n", b / a * 100);
    return 0;
}
发表于 2025-10-20 21:49:54 回复(0)
using System;

public class Program {
    public static void Main() {
        string[] input = Console.ReadLine().Split(" ");
        long c = long.Parse(input[0]);
        long d = long.Parse(input[1]);

        double morality = (double) d / c * 100;
        Console.WriteLine($"{morality:F3}%");

    }
}
发表于 2025-10-19 17:06:06 回复(0)
#include <stdio.h>

int main() {
    int c, d;
    float e;
    scanf("%d",&c);
    scanf("%d",&d);
    e=(float)d/c*100;
    printf("%.3f%%\n",e );
    }

发表于 2025-10-17 11:10:48 回复(0)
int main() {
    int c, d;
    float e;
    // while (scanf("%d %d", &a, &b) != EOF) { // 注意 while 处理多个 case
    //     // 64 位输出请用 printf("%lld") to
    //     printf("%d\n", a + b);
    // }
    scanf("%d %d\r\n", &c, &d);
    e = 100.000 * d / c;
    printf("%.3f%%\n", e);          //%%  输出百分号
    return 0;
}
发表于 2025-10-02 11:06:27 回复(0)
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            BigDecimal aa = new BigDecimal(in.nextInt());
            BigDecimal bb = new BigDecimal(in.nextInt());
            BigDecimal cc = bb.multiply(new BigDecimal(100)).divide(aa,3, RoundingMode.HALF_UP);
            System.out.println(cc+"%");
        }
    }


发表于 2025-09-29 22:45:47 回复(0)
#include<stdio.h> int main() { float c,d,f; printf("确诊人数:\n"); scanf("%f",&c); printf("死亡人数:\n"); scanf("%f",&d); f=d/c*100.0; printf("死亡率:%.3f%%",f); return 0; }</stdio.h>
发表于 2025-09-29 19:21:38 回复(0)
package main

import (
	"fmt"
)

func main() {
	c := 1
	d := 0
	var tmp float32
	fmt.Scan(&c, &d)
	tmp = float32(d) / float32(c) * 100
	fmt.Printf("%.3f%%", tmp)
}

发表于 2025-09-22 23:52:42 回复(0)
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();

        // 关键修正:先将 b 转为浮点数(*100.0),再除以 a,避免整数除法
        double c = (b*100.0)/a;

        System.out.printf("%.3f%%", c);

        in.close();
    }
}

总结:为什么用 double?

  1. 精度足够:double 的 15-17 位有效数字能覆盖题目中 10⁹ 级别的数值计算,避免精度丢失,确保最终结果符合 “保留三位小数” 的误差要求;
  2. 使用自然Java 中 100.0 默认是 double,无需额外加后缀,避免类型转换问题;
  3. 通用性强实际开发中,除非有明确的内存限制(如海量数据存储),否则优先用 double,它是浮点数计算的 “默认首选”,能应对绝大多数场景

整数除法的特性

在 Java 中,当两个 int 类型的变量进行除法运算(b/a)时,会执行 整数除法—— 即只保留商的整数部分,丢弃小数部分
  • 整数除法(int/int)会丢失小数部分,导致计算结果为 0。
  • 必须先通过 *100.0 或 *1.0 将整数转换为浮点数,确保除法为浮点数运算,才能得到正确的小数结果。



发表于 2025-09-20 12:45:47 回复(0)
z = input()
a = int(z.split()[0])
b = int(z.split()[1])
c = '%.3f'%(b / a*100)
print (c +'%')
发表于 2025-09-16 15:33:35 回复(0)
c,d=map(int,input().split())
a=1.0*(d/c)*100
print("%.3f"%a+"%")
发表于 2025-09-14 23:08:25 回复(0)
#include <stdio.h>
int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    printf("%.3f%%\n",(b*1000.0)/a*0.1);
    return 0;
}
发表于 2025-09-14 20:20:20 回复(0)