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
 
Author
2006Rocky Mountain Warmup

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath> using namespace std; char s[];
int an[]; int main()
{
an['A'] = ;an['B'] = ;an['C'] = ;an['D'] = ;an['F'] = ;
int i,j,k,l;
while(gets(s))
{
l = strlen(s);
bool bl = ;
double sum = ;
int n = ;
for(i = ;i<l;i++)
{
if(s[i] == ' ') continue;
if(s[i]>='A'&&s[i]<='D'||s[i] == 'F')
{
n++;
sum+=an[s[i]];
}
else
{
bl = ;
break;
}
}
if(bl)
{
cout<<"Unknown letter grade in input"<<endl;
}
else
{
printf("%.2lf\n",sum/n);
}
}
return ;
}

hdu2399GPA的更多相关文章

随机推荐

  1. OD调试3--reverseMe

    OD调试3:reverseMe.exe(reverse就是逆向的意思) 运行效果图: 1关于寄存器 寄存器就好比是CPU身上的口袋,方便CPU随时从里边拿出需要的东西来使用.今天的程序中涉及到九个寄存 ...

  2. C# using垃圾回收详解

    简介 定义一个范围,将在此范围之外释放一个或多个对象. 语法 using (Font font1 = new Font("Arial", 10.0f)) { } C# 语言参考 主 ...

  3. [转载]OpenSUSE 13.2/13.1 安装搜狗拼音输入法

    1. 添加 M17N 源: 13.2: sudo zypper ar -f http://download.opensuse.org/repositories/M17N/openSUSE_13.2/ ...

  4. [C++程序设计]函数模板

    定义函数模板的一般形 式为 template < typename T> 或 template <class T> 函数模板: 函数参数个数,函数体相同.参数类型不同 函数重载 ...

  5. C# is 与 as 运算符

    as运算符有一定的适用范围,它只适用于引用类型或可以为null的类型,而无法执行其他的转换,如值类型的转换以及用户自定义的类型转换,这类转换应该适用强制转换表达式来执行.as当转换不了的时候返回nul ...

  6. 2014第3周三JS进阶书籍

    本来想尝试每天回答或看已解决的3个问题来学习总结今天的知识点,看了下博文里面的问答,在问的和已解决的都提不起兴趣.就看了下知识库里面一些文章,把里面感觉好的段落再摘录一下,为自己再看时备忘. 第一阶段 ...

  7. cf478A Initial Bet

    A. Initial Bet time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  8. hdu 3874 Necklace(bit树+事先对查询区间右端点排序)

    Mery has a beautiful necklace. The necklace is made up of N magic balls. Each ball has a beautiful v ...

  9. laravel5.3 笔记一

    laravel5.3 笔记 安装环境 laravel环境,laravel中文学习论坛上面有相关的教程 创建应用 laravel new blog 其中blog就是你的应用的名字 数据迁移 php ar ...

  10. 【刷题 Python Tip】题目6~10

    [题目6]输出100以内的所有素数,素数之间以一个空格区分 from math import sqrt print ' '.join(str(key) for key in [x for x in x ...