HDU 4802-gpa (water)

Source: Internet
Author: User
GPA Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 1471 accepted submission (s): 902


Problem descriptionin 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

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,

An additional treatment is taken for special cases. some courses are based on "pass/not pass" policy, where stude ETS 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 ".
Inputthere 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.
Outputfor each test case, print the GPA (rounded to two decimal places) as the answer.
Sample Input
52 B3 D-2 P1 F3 A22 P2 N64 A3 A3 A4 A3 A3 A
 
Sample output
2.330.004.00
#include <iostream>#include <cmath>#include <cstdio>#include <cstring>using namespace std;#define ll long longint main(){  int n,x;char s[5];  while(~scanf("%d",&n))  {  int sum_c=0;  double sum_cs=0;  while(n--){scanf("%d %s",&x,s);if(s[0]=='P'||s[0]=='N')continue;sum_c+=x;double tem;if(strlen(s)==1){switch (s[0]){case 'A':tem=4;break;case 'B':tem=3;break;case 'C':tem=2;break;case 'D':tem=1.3;break;case 'F':tem=0;break;}}else{if(!strcmp(s,"A-"))tem=3.7;else if(!strcmp(s,"B+"))tem=3.3;else if(!strcmp(s,"B-"))tem=2.7;else if(!strcmp(s,"C+"))tem=2.3;else if(!strcmp(s,"C-"))tem=1.7;else if(!strcmp(s,"D-"))tem=1.0;}sum_cs+=(double)x*tem;}if(sum_c==0){puts("0.00");continue;}printf("%.2lf\n",sum_cs/(double)sum_c);  }  return 0;}

HDU 4802-gpa (water)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.