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. Cortex-M3寄存器等基础知识

    1.寄存器 CM3拥有R0~R15通用寄存器和一些特殊功能寄存器 R0~R12这些通用寄存器,复位初始值都是不可预料的 2.CM3有R0到R15的通用寄存器组 注:绝大部分的16位thumb只能访问R ...

  2. Windows安装TensorFlow-Docker Installation of TensorFlow on Windows

    TensorFlow是Google开发的进行Deep Learning的包,目前只是支持在Linux和OSX上运行.不过这个秋季或许就有支持Windows的版本出现了,那么对于使用Windows的开发 ...

  3. Django学习之路

    Django Website Collect django packages http://djangopackages.com/ django project http://code.djangop ...

  4. X-factor Chains(POJ3421 素数)

    X-factor Chains Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6212   Accepted: 1928 D ...

  5. 如何清空android ListView控件的内容

    第一种方法: listView.setAdapter(null); 第二种方法: listAdapter.clear(); listAdapter.notifyDataSetChanged() ; 满 ...

  6. python每次处理一个字符的三种方法

    python每次处理一个字符的三种方法 a_string = "abccdea" print 'the first' for c in a_string: print ord(c) ...

  7. 基于 Bootstrap 的扁平化 UI 开发包

    Flat UI是一款基于Bootstrap的扁平化前端UI工具包,Flat UI的组件外观设计非常清新和漂亮,Flat UI的组件包含按钮,输入框,组合按钮,复选框,单选按钮,标签,菜单,进度条和滑块 ...

  8. Seletion Sort

    referrence: GeeksforGeeks The selection sort algorithm sorts an array by repeatedly finding the mini ...

  9. mongodb导入导出备份恢复

    mongodb数据库同样离不开必要的维护,如备份.恢复.导入.导出. 其实备份和恢复比导入和导出要方便些,而且一般不会出错,所以大部分时候使用备份和恢复操作就可以了 1. 备份Mongodb mong ...

  10. 【转】【漫画解读】HDFS存储原理

    根据Maneesh Varshney的漫画改编,以简洁易懂的漫画形式讲解HDFS存储机制与运行原理. 一.角色出演 如上图所示,HDFS存储相关角色与功能如下: Client:客户端,系统使用者,调用 ...