2018.6.1(hdu 2061 Treasure the new start, freshmen!)

此题并不难,主要是有一些坑
1:题干没说credts,score为整数,可能为小数
2:输出格式,两个数据间有空行,最后一个数据输出后无空行

#include<iostream>
#include<cstdio>
using namespace std;

int main()
{
    int N;
    cin>>N;
    while(N--)
    {
        int k;
        bool flag=0;
        scanf("%d",&k);

        double total_c=0;
        double total_c_s=0;
        for(int i=1;i<=k;i++)
        {
            char course[40];
            double credits,score;//将credits,score定义成浮点型
            scanf("%s%lf%lf",course,&credits,&score);

            total_c+=credits;
            total_c_s+=credits*score;

            if(score<60)
                flag=1;
        }

        if(flag)
            printf("Sorry!\n");
        else
            printf("%.2lf\n",total_c_s/total_c);

        if(N>0)//控制换行
            printf("\n");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/violet_ljp/article/details/80533271