Problem : 1202 ( The calculation of GPA )

Losers always whine about their best. Winners go home and fuck the prom queen。
很操蛋却非常有意思的题目,注意变量的类型,学分能最后为0?分数的范围?很操蛋。
#include<iostream>
using namespace std;
void main()
{
	int n,temp=0;
	double cent,score=0,sum=0,count=0;
	while(cin>>n)
	{
		sum=0;count=0;
		for(int i=0;i<n;i++)
		{
			cin>>cent>>score;
			
			if(score!=-1)
			{
				count+=cent;
				if(score>=90)
					temp=4;
				else if(score>=80)
					temp=3;
				else if(score>=70)
					temp=2;
				else if(score>=60)
					temp=1;
				else if(score>=0)
					temp=0;
				sum+=cent*temp;
			}

		}
		 if(count==0)
			cout<<-1<<endl;
		else
			printf("%.2lf\n",sum/count);
	}


}

你可能感兴趣的:(Problem : 1202 ( The calculation of GPA ))