CGPA, the Golden Egg!

Jakaria_MU Intra Metropolitan Univer...
Limits 1s, 512 MB

Jenith is a student of CSE of Metropolitan University (MU). Recently her fifth term’s result has been published. She obtained CGPA 4 out of 4. Her classmates ask her to calculate their CGPA. Actually she helps her friends to calculate their CGPA from the first term. Sometimes she feels bore, so she wants to write a program now that will help her friends to calculate their CGPA. As you are a very good programmer she needs your help.

CGPA stands for “Cumulative Grade Point Average”. It is calculated based on all the courses you take along with the total number of credit hours. The total marks or numeral grades of a course is multiplied by the total credits of that course. Then summing the results of all the courses divide by the total credits of a term or semester you will get your CGPA.

In Metropolitan University important courses including major and non-major courses carry 3 to 4 credits and some less important courses including lab courses carry 1 to 2 credits.

Marks RangeGradeGrade Point


The first line of input contains an integer T (T ≤ 50) denoting the number of test cases. Next line contains an integer C the number of courses you take in a term or semester. Next C lines contains two numbers (can be float or double) m, n (0 ≤ m ≤ 100, n ≥ 1), the marks of a course and the credit of that course.


For each test case print the case no and print the floating point result R (two digits after decimal) that denotes your CGPA. If your input m contains less than 40 then print "Sorry, you have failed in F courses!" Where F is an integer that denotes the number of courses you have failed.


79.5  3
88  3
100  3
75  2
97  3
92  1.5
69  2
75  3
55  3
56.5  2
55.5  3
36  3
25  4 
Case 1: 3.89
Case 2: 3.52
Case 3: Sorry, you have failed in 2 courses!

Note: If you have failed in 1 course, then you have to print "Sorry, you have failed in 1 course!". Otherwise print "Sorry, you have failed in F courses!", where F denotes the the total number of courses you have failed.


Login to submit.


79% Solution Ratio
nazmul.me92Earliest, Jul '17
Nasif_44thFastest, 0.0s
Mili290Lightest, 0 B
touhidurrrShortest, 267B
Toph uses cookies. By continuing you agree to our Cookie Policy.