GPA |
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB |
Total submit users: 165, Accepted users: 160 |
Problem 10880 : No special judgement |
Problem description |
Each 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. |
Input |
The input file will contain 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. |
Output |
Each line of input will result in exactly one line of output. If all upper case letters on a particular 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 F B F F C C A D C E F |
Sample Output |
2.00 1.83 Unknown letter grade in input |
Problem Source |
Rocky Mountain 2006 |
Submit Discuss Judge Status Problems Ranklist |
本人的算法比较差,现在开始把我每次做的ACM,都写上:
#include <iostream> #include"stdio.h" #include<string> #include<map> using namespace std; int main(int argc, char *argv[]) { map<const char,int> m; char in[100000]; int len; bool flag = true; int sum = 0; m['A'] = 4; m['B'] = 3; m['C'] = 2; m['D'] = 1; m['F'] = 0; while(gets(in)) { len = strlen(in)+1; for(int i=0; i<len; i+=2) { if(m[in[i]]==0&&in[i]!='F') { flag = false; } sum+=m[in[i]]; } if(false == flag) { cout<<"Unknown letter grade in input"<<endl; } else { printf("%.2lf/n",((double)sum)/(len/2)); } sum = 0; len = 0; flag = true; } return 0; } 其中gets我都不是很会用,记住它也会将空格读取进来的.
gets
【1】函数:gets
【2】头文件:stdio.h
【3】功能:从stdin流中读取字符串,直至接受到换行符或EOF时停止,并将读取的结果存放在str指针所指向的字符数组中。换行符不作为读取串的内容,读取的换行符被转换为null值,并由此来结束字符串。
【4】注意:本函数可以无限读取,不会判断上限,所以程序员应该确保str的空间足够大,以便在执行读操作时不发生溢出。
【5】示例:
#include"stdio.h"
void main()
{
char str1[5];
gets(str1);
printf("%s/n",str1);
}
|