hdu 2399 GPA

题意:



#include<iostream>
#include<string>
#include<iomanip>
using namespace std;

int main(){
    string str;
    while(getline(cin,str)){
        int num = 0;
        double sum = 0;
        for(int i=0;i<str.length();i++){
            if(str[i]!=' '){
                // 计数
                num++;
                switch(str[i]){
                case 'A':
                    sum+=4;
                    break;
                case 'B':
                    sum+=3;
                    break;
                case 'C':
                    sum+=2;
                    break;
                case 'D':
                    sum+=1;
                    break;
                case 'F':
                    break;
                default:
                    num = 0;
                    break;
                }
            }
            // 判断num是否等于0
            if(!num){
                break;
            }
        }
        if(!num){
            cout<<"Unknown letter grade in input"<<endl;
        }else{
            sum = sum / num;
            cout<<fixed<<setprecision(2);
            cout<<sum<<endl;
        }
    }
    return 0;
}




GPA

平均绩点

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3137    Accepted Submission(s): 1867


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.) 
每一门课程的成绩用分别用A,B,C,D,F表示。(注意这里没有E)
The grade A indicates superior achievement , whereas F stands for failure. 
A表示成绩优秀,F表示不及格。
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.
 为了计算GPA,A,B,C,D,F分别代表4,3,2,1,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. 
然后输出GPA,结果精确到两位小数。
Otherwise, the message "Unknown letter grade in input" will be printed.
 否则,输出提示信息“ Unknown letter grade in input ”;

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
 

Source

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值