hdu 1202 The calculation of GPA

来源:互联网 发布:推荐信 出国留学 知乎 编辑:程序博客网 时间:2024/05/18 22:11

题目:点击打开链接

题目不难,读懂题意就行,

代码有错误,还没AC,想看阅兵大哭

#include<cstdio>#include<cstring>#include<cmath>#include<iostream>using namespace std;int main(){    int n,m;    float s,p,ans=0,sum=0;    while(scanf("%d",&n)!=EOF)    {        for(int i=0;i<n;i++)        {            cin>>s>>p;            if(p>=90&&p<=100) m=4;            else if(p>=60&&p<=69) m=1;            else if(p>=70&&p<=79) m=2;            else if(p>=80&&p<=89) m=3;            else m=0;            if(p==-1)            {                ans=0;                sum=0;                break;            }            ans+=s;            sum+=s*m;        }        if(ans==0||sum==0) printf("-1\n");        else  printf("%.2lf\n",sum/ans);    }    return 0;}


害羞

0 0