GPA
Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 317 accepted submission (s): 194
Problem descriptioneach course grade is one of the following five letters: A, B, C, D, and F. (Note that there is no Grade E .) the grade A indicates superior achievement, whereas F stands for failure. in order to calculate the GPA, the letter grades A, B, C, D, and F are assigned the following grade points, respectively: 4, 3, 2, 1, and 0.
Inputthe input file will contain in data for one or more test cases, one test case per line. On each line there will be one or more upper case letters, separated by blank spaces.
Outputeach line of input will result in exactly one line of output. if all upper case letters on a participant line of input came from the set {A, B, C, D, F} Then the output will consist of the GPA, displayed with a precision of two decimal places. otherwise, the message "unknown letter grade in input" will be printed.
Sample Input
A B C D FB F F C C AD C E F
Sample output
2.001.83Unknown letter grade in input
# Include <iostream> <br/> # include <cmath> <br/> # include <cstring> <br/> # include <map> <br/> # include <Algorithm> <br/> using namespace STD; </P> <p> int main () <br/> {<br/> freopen ("in1.txt", "r", stdin); <br/> string S; <br/> int Len; <br/> double sum; <br/> int count; <br/> while (Getline (CIN, S )) <br/> {<br/> Len = S. length (); <br/> sum = 0; <br/> COUNT = 0; <br/> bool flag = false; <br/> for (INT I = 0; I <Len; I ++) <br/>{< br/> If (s [I] = '') <br/> continue; <br/> If (s [I] = 'A') <br/> {<br/> sum + = 4; <br/> count ++; <br/>}< br/> else <br/> If (s [I] = 'B') <br/>{< br/> sum + = 3; <br/> count ++; <br/>}< br/> else <br/> If (s [I] = 'C ') <br/>{< br/> sum + = 2; <br/> count ++; <br/>}< br/> else <br/> If (s [I] = 'D') <br/>{< br/> sum + = 1; <br/> count ++; <br/>}< br/> else <br/> If (S [I] = 'F') <br/>{< br/> count ++; <br/>}< br/> else <br/>{< br/> flag = true; <br/> cout <"unknown letter grade in input" <Endl; <br/> break; <br/>}< br/> If (! Flag) <br/>{< br/> cout <(INT) sum/count; <br/> cout <". "; <br/> double TMP = sum/(double) count; <br/> cout <(INT) (TMP * 10.0) % 10; <br/> cout <(INT) (TMP * 100.0) % 10; <br/> cout <Endl; <br/>}< br/>