zoukankan      html  css  js  c++  java
  • [HDU 1202] The calculation of GPA

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1202

    题目不难,注意一些细节问题:

    • 浮点数初始化或者进行比较的时候默认加上个 .0
    • 认真分析题目中的各项数据应该用什么类型的
    • 在测试用例不确定的情况下,还是用while来无限次输入吧
    /*
     * 用while循环
     * 学分和成绩数据是浮点数
     */
    
    import java.util.Scanner;
    
    public class Main {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            while (scanner.hasNext()) {
                int n = scanner.nextInt();
                double x,y;
                double suma = 0.0,sumb = 0.0;
                while (n-- > 0) {
                    x = scanner.nextDouble();
                    y = scanner.nextDouble();
                    if (y == -1.0)
                        continue;
                    suma += x;
                    sumb = sumb + x * dian(y);
                }
                if (suma == 0.0) {
                    System.out.println(-1);
                } else {
                    double ans = sumb / suma;
                    System.out.printf("%.2f", ans);
                    System.out.println();
                }
            }
        }
    
        public static int dian(double y) {
            if (y >= 90.0)
                return 4;
            else if (y >= 80.0)
                return 3;
            else if (y >= 70.0)
                return 2;
            else if (y >= 60.0)
                return 1;
            else
                return 0;
        }
    }
    
  • 相关阅读:
    kvm-在virsh环境中改变CD媒介
    Mysql5.7.16安装过程
    Pycharm 2016专业版激活方式
    Tornado
    Django
    python day18
    python day16
    day15
    python day11
    B10-openstack高可用(t版)-nova计算节点节点集群部署
  • 原文地址:https://www.cnblogs.com/youpeng/p/10545723.html
Copyright © 2011-2022 走看看