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

    以前和一个队员交流过的,当时他说他用了字符串表示的方法做的,想起来觉得有点麻烦

    今天做了一下,果然有点坑,也是看了题解才知道坑的地方

    1.如果总分太小了,也就小于1e-9那种,会导致OLE。

    2.分母不为0这个细心点都应该知道的。

    3.但是没有判断分母为0也AC了。

     1 #include <stdio.h>
     2 #include <iostream>
     3 using namespace std;
     4 #include <math.h>
     5 
     6 const double eps = 1e-9;
     7 
     8 int get(double s)
     9 {
    10     if(s >= 90 && s <= 100) return 4;
    11     else if(s >= 80) return 3;
    12     else if(s >= 70) return 2;
    13     else if(s >= 60) return 1;
    14     return 0;
    15 }
    16 
    17 int main()
    18 {
    19     int n;
    20     while(scanf("%d",&n)!=EOF)
    21     {
    22         double sum =0 , tot=0;
    23         double pnt,sco;
    24         for(int i=0;i<n;i++)
    25         {
    26             cin>>pnt>>sco;
    27             int t=get(sco);
    28             sum += t*pnt;
    29             tot += pnt;
    30         }
    31         if(fabs(sum) < eps || tot<=0.0) printf("-1
    ");
    32         else
    33         {
    34             double ans = sum/tot;
    35             printf("%.2lf
    ",ans);
    36         }
    37     }
    38     return 0;
    39 }
    View Code
  • 相关阅读:
    AtomicReference与volatile的区别
    深度剖析ConcurrentHashMap(转)
    ConcurrentHashMap原理分析
    Java Stack源码分析
    Fail-Fast机制详解
    TreeSet源码分析
    状态(State)模式
    原型(Prototype)模式
    职责连模式
    观察者模式(Observer)
  • 原文地址:https://www.cnblogs.com/cton/p/3436790.html
Copyright © 2011-2022 走看看