hdu 2061 注意格式要求

 If there are K(K > 0) courses, the i-th course has the credit Ci, your score Si, then the result GPA is
GPA = (C1 * S1 + C2 * S2 +……+Ci * Si……) / (C1 + C2 + ……+ Ci……) (1 <= i <= K, Ci != 0)
If there is a 0 <= Si < 60, The GPA is always not existed.

 


Input
The first number N indicate that there are N test cases(N <= 50). In each case, there is a number K (the total courses number), then K lines followed, each line would obey the format: Course-Name (Length <= 30) , Credits(<= 10), Score(<= 100).
Notice: There is no blank in the Course Name. All the Inputs are lega
Output
Output the GPA of each case as discribed above, if the GPA is not existed, ouput:"Sorry!", else just output the GPA value which is rounded to the 2 digits after the decimal point. There is a blank line between two test cases.
Sample Input
  
  
2 3 Algorithm 3 97 DataStruct 3 90 softwareProject 4 85 2 Database 4 59 English 4 8
Sample Output
  
  
90.10 Sorry!

 题目:GPA = (C1 * S1 + C2 * S2 +……+Ci * Si……) / (C1 + C2 + ……+ Ci……) (1 <= i <= K, Ci != 0)用这个公式计算总分
但成绩有小于60的输出Sorry!

并且注意没输出一组数据的结果,后面就空一行,但最后一次不空

还要注意学分和成绩只能用double

作为计算总数的变量别忘记先清零

数组稍开大一点,防止溢出

#include<stdio.h>
 struct news{
              char nam[32];
              double cred;
              double sco;
            }a[105];
int main()
{
    int n,m,i,p;double sum,num;
   
    scanf("%d",&n);
    while(n--)
    {
        sum=num=0.0;p=0;
        scanf("%d",&m);
        getchar();
        for(i=0;i<m;i++)
        scanf("%s %lf %lf",a[i].nam,&a[i].cred,&a[i].sco);
        for(i=0;i<m;i++)
        {
          if(a[i].sco<60)
                     p=1; 
                     sum+=a[i].cred*a[i].sco;
                     num+=a[i].cred;
          }
          if(p) printf("Sorry!\n");
            else{
                      sum=sum/num;
                     printf("%.2lf\n",sum);
                 }
         
          if(n) printf("\n");
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

洋葱ycy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值