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. Entity Framework数据库迁移

    1.启用数据迁移: enable-Migrations2.增加一条数据库迁移指令:add-Migrations 必须带上一个版本名称,比如AddUsernamePassword完整的指令:add-Mi ...

  2. protobuf 参考资料

    Protocol Buffers 官网下载地址:https://developers.google.com/protocol-buffers/docs/downloads Protocol Buffe ...

  3. 【Solr专题之九】SolrJ教程

    一.SolrJ基础 1.相关资料 API:http://lucene.apache.org/solr/4_9_0/solr-solrj/ apache_solr_ref_guide_4.9.pdf:C ...

  4. load average[zhuan]

    load average值的含义 单核处理器 假设我们的系统是单CPU单内核的,把它比喻成是一条单向马路,把CPU任务比作汽车.当车不多的时候,load <1:当车占满整个马路的时候 load= ...

  5. 创建简单的ajax对象

    oAjax=               oAjax=                     oAjax.open('GET', url,                               ...

  6. CSS3匹配屏幕横竖状态

    @media是css3中新定义的,功能非常强大,下面简单讲解一下用css3的@media orientation匹配手机屏幕是横屏还是竖屏. 顾名思义PC是无法匹配横竖屏的,所以orientation ...

  7. Ubuntu14.04LST 安装Oracle SQL Developer 4.0.2

    1:Oracle SQL Developer 4.0.2下载链接: http://www.oracle.com/technetwork/developer-tools/sql-developer/do ...

  8. log4j 将日志记录到数据库

    需要以下jar包: ---log4j commons-loggin-1.1.1.jar log4j-1.2.16.jar ---mysql mysql-connector-java-5.1.15-bi ...

  9. 二分图带权最大独立集 网络流解决 hdu 1569

    方格取数(2) Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  10. java开发中遇到的问题及解决方法(持续更新)

    摘自 http://blog.csdn.net/pony12/article/details/38456261 java开发中遇到的问题及解决方法(持续更新) 工作中,以C/C++开发为主,难免与其他 ...