首页 > ACM题库 > HDU-杭电 > HDU 4802-GPA[解题报告]HOJ
2015
09-18

HDU 4802-GPA[解题报告]HOJ

GPA

问题描述 :

In college, a student may take several courses. for each course i, he earns a certain credit (ci), and a mark ranging from A to F, which is comparable to a score (si), according to the following conversion table
Pocket Cube

The GPA is the weighted average score of all courses one student may take, if we treat the credit as the weight. In other words,
Pocket Cube

An additional treatment is taken for special cases. Some courses are based on “Pass/Not pass” policy, where stude nts earn a mark “P” for “Pass” and a mark “N” for “Not pass”. Such courses are not supposed to be considered in computation. These special courses must be ignored for computing the correct GPA.
Specially, if a student’s credit in GPA computation is 0, his/her GPA will be “0.00”.

输入:

There are several test cases, please process till EOF.
Each test case starts with a line containing one integer N (1 <= N <= 1000), the number of courses. Then follows N lines, each consisting the credit and the mark of one course. Credit is a positive integer and less than 10.

输出:

There are several test cases, please process till EOF.
Each test case starts with a line containing one integer N (1 <= N <= 1000), the number of courses. Then follows N lines, each consisting the credit and the mark of one course. Credit is a positive integer and less than 10.

样例输入:

5
2 B
3 D-
2 P
1 F
3 A
2
2 P
2 N
6
4 A
3 A
3 A
4 A
3 A
3 A

样例输出:

2.33
0.00
4.00

Hint
For the first test case: GPA =(3.0 * 2 + 1.0 * 3 + 0.0 * 1 + 4.0 * 3)/(2 + 3 + 1 + 3) = 2.33 For the second test case: because credit in GPA computation is 0(P/N in additional treatment), so his/her GPA is “0.00”.

邀请赛的水题。。

代码如下:

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

int main(){
	#ifndef ONLINE_JUDGE
	freopen("data.txt","r",stdin);
	#endif
	ios::sync_with_stdio(false);
	int n;
	while(cin>>n){
		double c=0,cs=0;
		for(int i=0;i<n;++i){
			double cr;
			string mark;
			cin>>cr>>mark;
			if(mark=="P"||mark=="N")continue;
			else if(mark=="A"){c+=cr;cs+=cr*4.0;}
			else if(mark=="A-"){c+=cr;cs+=cr*3.7;}
			else if(mark=="B+"){c+=cr;cs+=cr*3.3;}
			else if(mark=="B"){c+=cr;cs+=cr*3.0;}
			else if(mark=="B-"){c+=cr;cs+=cr*2.7;}
			else if(mark=="C+"){c+=cr;cs+=cr*2.3;}
			else if(mark=="C"){c+=cr;cs+=cr*2.0;}
			else if(mark=="C-"){c+=cr;cs+=cr*1.7;}
			else if(mark=="D"){c+=cr;cs+=cr*1.3;}
			else if(mark=="D-"){c+=cr;cs+=cr*1.0;}
			else if(mark=="F"){c+=cr;cs+=cr*0;}
		}
	//	cout<<cs<<' '<<c<<endl;
		if(c==0)cout<<"0.00"<<endl;
		else cout<<setiosflags(ios::fixed)<<setprecision(2)<<cs/c<<endl;
	}
	return 0;
}

参考:http://blog.csdn.net/u010734277/article/details/24536661


  1. 擦,哪来的那么多愤青?没错,我们现在的确还不够好,但是这样就足以完全否定我们自己吗?看看棒子国,再看看我们自己,别忘了我们曾经处在同一起跑线上,你真的能说我们一点进步都没有?我们现在还是不够好,但是这还是你自己的国家,就比如你妈虽然是个市井大妈,有各种不

  2. 想一想,是给谁争呢?他把白头山给人家告诉你了吗?他把白龙尾岛给了人家告诉你了吗?给人家当枪使还帮人家数钱,真是可怜又可悲!

  3. 想一想,是给谁争呢?他把白头山给人家告诉你了吗?他把白龙尾岛给了人家告诉你了吗?给人家当枪使还帮人家数钱,真是可怜又可悲!

  4. 想一想,是给谁争呢?他把白头山给人家告诉你了吗?他把白龙尾岛给了人家告诉你了吗?给人家当枪使还帮人家数钱,真是可怜又可悲!

  5. 想一想,是给谁争呢?他把白头山给人家告诉你了吗?他把白龙尾岛给了人家告诉你了吗?给人家当枪使还帮人家数钱,真是可怜又可悲!

  6. 想一想,是给谁争呢?他把白头山给人家告诉你了吗?他把白龙尾岛给了人家告诉你了吗?给人家当枪使还帮人家数钱,真是可怜又可悲!

  7. 想一想,是给谁争呢?他把白头山给人家告诉你了吗?他把白龙尾岛给了人家告诉你了吗?给人家当枪使还帮人家数钱,真是可怜又可悲!

  8. 想一想,是给谁争呢?他把白头山给人家告诉你了吗?他把白龙尾岛给了人家告诉你了吗?给人家当枪使还帮人家数钱,真是可怜又可悲!

  9. 想一想,是给谁争呢?他把白头山给人家告诉你了吗?他把白龙尾岛给了人家告诉你了吗?给人家当枪使还帮人家数钱,真是可怜又可悲!

  10. 想一想,是给谁争呢?他把白头山给人家告诉你了吗?他把白龙尾岛给了人家告诉你了吗?给人家当枪使还帮人家数钱,真是可怜又可悲!

  11. 想一想,是给谁争呢?他把白头山给人家告诉你了吗?他把白龙尾岛给了人家告诉你了吗?给人家当枪使还帮人家数钱,真是可怜又可悲!

  12. 想一想,是给谁争呢?他把白头山给人家告诉你了吗?他把白龙尾岛给了人家告诉你了吗?给人家当枪使还帮人家数钱,真是可怜又可悲!

  13. 想一想,是给谁争呢?他把白头山给人家告诉你了吗?他把白龙尾岛给了人家告诉你了吗?给人家当枪使还帮人家数钱,真是可怜又可悲!

  14. 想一想,是给谁争呢?他把白头山给人家告诉你了吗?他把白龙尾岛给了人家告诉你了吗?给人家当枪使还帮人家数钱,真是可怜又可悲!

  15. 想一想,是给谁争呢?他把白头山给人家告诉你了吗?他把白龙尾岛给了人家告诉你了吗?给人家当枪使还帮人家数钱,真是可怜又可悲!

  16. 想一想,是给谁争呢?他把白头山给人家告诉你了吗?他把白龙尾岛给了人家告诉你了吗?给人家当枪使还帮人家数钱,真是可怜又可悲!