• 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
  • 相关阅读:
    汉语-词语-转世:百科
    汉语-词语-往生:百科
    中缀表达式值
    车厢调度(train.cpp)
    字符串匹配问题
    计算(calc.cpp)
    2、括弧匹配检验
    2058 括号序列
    7909:统计数字
    1007. 计算余数
  • 原文地址:https://www.cnblogs.com/cton/p/3436790.html
Copyright © 2020-2023  润新知