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. 提示框的优化之自定义Toast组件之(一)Toast组件的布局实现

    开发步骤:  在res下layout下创建一个Toast的布局资源文件toast_customer.xml  在最外层布局组件中为该布局添加android:id属性  //toast_custo ...

  2. SQL Server一些常见却不太记得住的命令

    一.数据库大小查询 1. exec sp_spaceused '表名'          --(SQL统计数据,大量事务操作后可能不准)2. exec sp_spaceused '表名', true  ...

  3. 常用网站--前端开发类+网页设计类+平面素材类+flash类

    前端开发类 animate CSS 前端开发网 我爱CSS 大家网 W3School jQuery开发技术详解教程视频 jQuery中文社区 jQueryChina 网页设计类 禅意花园 CSS Do ...

  4. hdu1166 经典线段入门

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  5. codeforces 340D Bubble Sort Graph(dp,LIS)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud  Bubble Sort Graph Iahub recently has lea ...

  6. C++程序设计实践指导1.1删除序列中相同的数改写要求实现

    改写要求1:改写为以指针为数据结构 #include <iostream> #include <cstdlib> using namespace std; class ARP ...

  7. php的一些小笔记--字符串

    字符串: 转换ASCII函数: ord($tring) 返回ASCII,chr($ASCII)返回相应的字符 把字符串切割成数据的函数: chunk_split($string,$len) chunk ...

  8. python3.4 伪装成浏览器获取页面信息失败

    最近学了下网络爬虫,打算从一个网站上提取点东西,自己练练手,刚开始还从这个网站上取了正确的html,后来百般尝试还是不能取正确的html,希望能得到大家的帮助~ 我刚开始的代码是: 1 url=&qu ...

  9. Django学习(五) 定义视图以及页面模板

    请求解析一般都是通过请求的request获取一定参数,然后根据参数做一定业务逻辑判断,这其中可能包括查询数据库,然后将需要返回的数据封装成一个HttpResponse返回. 代码如下: 这是一个简单的 ...

  10. log4net使用(包括单个文件和按日期生成多个文件)

    1.log4net生成单个文件 直接将这段代码考到config中即可用 <log4net> <!--定义输出到文件中--> <appender name="Lo ...